From c93e8eeedae0eca21521c3c645655bb94336d7e3 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Wed, 21 Jan 2015 14:22:10 -0800 Subject: [PATCH] Fetch account-by-id from accounts cache during auth When authenticating users to Gerrit we can actually use the accounts cache without necessarily fetching them again from DB. Accounts are not very volatile and once a user gets provisioned its ID cannot be changed anymore: it is safe then to use the cache instead of overloading the underlying DB. NOTE: The amount of load taken out of DB can be significant when robot users (e.g. build jobs) are constantly polling Gerrit for changes over HTTP connections. Example: 10 slaves on 10 repos doing 100 polls/day would have generated 10k identical SQL queries per day. Change-Id: I861ab81015e5f559020b3565fbc3bd5d38c31146 --- .../java/com/google/gerrit/server/account/AccountManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java index 62615c6a2c..cdddfa618d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java @@ -118,8 +118,8 @@ public class AccountManager { } else { // Account exists - Account act = db.accounts().get(id.getAccountId()); - if (act == null || !act.isActive()) { + Account act = byIdCache.get(id.getAccountId()).getAccount(); + if (!act.isActive()) { throw new AccountException("Authentication error, account inactive"); }