use of com.google.gerrit.server.config.CachedPreferences in project gerrit by GerritCodeReview.
the class AccountCacheImpl method get.
@Override
public Map<Account.Id, AccountState> get(Set<Account.Id> accountIds) {
try {
try (Repository allUsers = repoManager.openRepository(allUsersName)) {
// Get the default preferences for this Gerrit host
Ref ref = allUsers.exactRef(RefNames.REFS_USERS_DEFAULT);
CachedPreferences defaultPreferences = ref != null ? defaultPreferenceCache.get(ref.getObjectId()) : DefaultPreferencesCache.EMPTY;
Set<CachedAccountDetails.Key> keys = Sets.newLinkedHashSetWithExpectedSize(accountIds.size());
for (Account.Id id : accountIds) {
Ref userRef = allUsers.exactRef(RefNames.refsUsers(id));
if (userRef == null) {
continue;
}
keys.add(CachedAccountDetails.Key.create(id, userRef.getObjectId()));
}
ImmutableMap.Builder<Account.Id, AccountState> result = ImmutableMap.builder();
for (Map.Entry<CachedAccountDetails.Key, CachedAccountDetails> account : accountDetailsCache.getAll(keys).entrySet()) {
result.put(account.getKey().accountId(), AccountState.forCachedAccount(account.getValue(), defaultPreferences, externalIds));
}
return result.build();
}
} catch (IOException | ExecutionException e) {
throw new StorageException(e);
}
}
use of com.google.gerrit.server.config.CachedPreferences in project gerrit by GerritCodeReview.
the class Accounts method read.
private Optional<AccountState> read(Repository allUsersRepository, Account.Id accountId) throws IOException, ConfigInvalidException {
AccountConfig cfg;
CachedPreferences defaultPreferences;
try (Timer0.Context ignored = readSingleLatency.start()) {
cfg = new AccountConfig(accountId, allUsersName, allUsersRepository).load();
defaultPreferences = CachedPreferences.fromConfig(VersionedDefaultPreferences.get(allUsersRepository, allUsersName));
}
return AccountState.fromAccountConfig(externalIds, cfg, defaultPreferences);
}
use of com.google.gerrit.server.config.CachedPreferences in project gerrit by GerritCodeReview.
the class DefaultConfigCacheIT method canLoadAtSpecificRev.
@Test
public void canLoadAtSpecificRev() throws Exception {
// Set a value to make sure we have custom preferences set
DiffPreferencesInfo update = new DiffPreferencesInfo();
update.lineLength = 1337;
gApi.config().server().setDefaultDiffPreferences(update);
ObjectId oldRev = currentRev();
CachedPreferences before = defaultPreferencesCache.get();
// Mutate the preferences
DiffPreferencesInfo update2 = new DiffPreferencesInfo();
update2.lineLength = 815;
gApi.config().server().setDefaultDiffPreferences(update2);
assertThat(oldRev).isNotEqualTo(currentRev());
assertThat(defaultPreferencesCache.get()).isNotEqualTo(before);
assertThat(defaultPreferencesCache.get(oldRev)).isEqualTo(before);
}
use of com.google.gerrit.server.config.CachedPreferences in project gerrit by GerritCodeReview.
the class DefaultConfigCacheIT method invalidatesOldValue.
@Test
public void invalidatesOldValue() throws Exception {
CachedPreferences before = defaultPreferencesCache.get();
DiffPreferencesInfo update = new DiffPreferencesInfo();
update.lineLength = 123;
gApi.config().server().setDefaultDiffPreferences(update);
assertThat(before).isNotEqualTo(defaultPreferencesCache.get());
}
Aggregations