Search in sources :

Example 1 with CachedPreferences

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);
    }
}
Also used : Account(com.google.gerrit.entities.Account) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) StorageException(com.google.gerrit.exceptions.StorageException) CachedPreferences(com.google.gerrit.server.config.CachedPreferences)

Example 2 with CachedPreferences

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);
}
Also used : Timer0(com.google.gerrit.metrics.Timer0) CachedPreferences(com.google.gerrit.server.config.CachedPreferences)

Example 3 with CachedPreferences

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);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) CachedPreferences(com.google.gerrit.server.config.CachedPreferences) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with CachedPreferences

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());
}
Also used : DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) CachedPreferences(com.google.gerrit.server.config.CachedPreferences) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CachedPreferences (com.google.gerrit.server.config.CachedPreferences)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Account (com.google.gerrit.entities.Account)1 StorageException (com.google.gerrit.exceptions.StorageException)1 Timer0 (com.google.gerrit.metrics.Timer0)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1