Package com.google.gerrit.server.account
Interface AccountCache
- All Known Implementing Classes:
AccountCacheImpl
public interface AccountCache
Caches important (but small) account state to avoid database hits.
-
Method Summary
Modifier and TypeMethodDescriptionget
(Account.Id accountId) Returns anAccountState
instance for the given account ID.get
(Set<Account.Id> accountIds) Returns aMap
ofAccount.Id
toAccountState
for the given account IDs.getByUsername
(String username) Returns anAccountState
instance for the given username.getEvenIfMissing
(Account.Id accountId) Returns anAccountState
instance for the given account ID.getFromMetaId
(Account.Id accountId, org.eclipse.jgit.lib.ObjectId metaId) Returns anAccountState
instance for the given account ID at the givenmetaId
ofRefNames.refsUsers(com.google.gerrit.entities.Account.Id)
ref.
-
Method Details
-
get
Returns anAccountState
instance for the given account ID. If not cached yet the account is loaded. ReturnsOptional.empty()
if the account is missing.- Parameters:
accountId
- ID of the account that should be retrieved- Returns:
AccountState
instance for the given account ID, if no account with this ID existsOptional.empty()
is returned
-
get
Returns aMap
ofAccount.Id
toAccountState
for the given account IDs. If not cached yet the accounts are loaded. If an account can't be loaded (e.g. because it is missing), the entry will be missing from the result.Loads accounts in parallel if applicable.
- Parameters:
accountIds
- IDs of the account that should be retrieved- Returns:
Map
ofAccount.Id
toAccountState
instances for the given account IDs, if an account can't be loaded (e.g. because it is missing), the entry will be missing from the result
-
getEvenIfMissing
Returns anAccountState
instance for the given account ID. If not cached yet the account is loaded. Returns an emptyAccountState
instance to represent a missing account.This method should only be used in exceptional cases where it is required to get an account state even if the account is missing. Callers should leave a comment with the method invocation explaining why this method is used. Most callers of
AccountCache
should useget(Account.Id)
instead and handle the missing account case explicitly.- Parameters:
accountId
- ID of the account that should be retrieved- Returns:
AccountState
instance for the given account ID, if no account with this ID exists an emptyAccountState
instance is returned to represent the missing account
-
getByUsername
Returns anAccountState
instance for the given username.This method first loads the external ID for the username and then uses the account ID of the external ID to lookup the account from the cache.
- Parameters:
username
- username of the account that should be retrieved- Returns:
AccountState
instance for the given username, if no account with this username exists or if loading the external ID failsOptional.empty()
is returned
-
getFromMetaId
Returns anAccountState
instance for the given account ID at the givenmetaId
ofRefNames.refsUsers(com.google.gerrit.entities.Account.Id)
ref.The caller is responsible to ensure the presence of
metaId
and the corresponding meta ref. The method does not populateAccountState.defaultPreferences()
.- Parameters:
accountId
- ID of the account that should be retrieved.metaId
- the sha1 of commit inRefNames.refsUsers(com.google.gerrit.entities.Account.Id)
ref.- Returns:
AccountState
instance for the given account ID at specific sha1metaId
.
-