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
This commit is contained in:
Luca Milanesio
2015-01-21 14:22:10 -08:00
committed by Shawn Pearce
parent 7ab817371e
commit c93e8eeeda

View File

@@ -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");
}