Remove access of groups related db tables from AccountCacheImpl

Change-Id: I30656f8902be4c0271e57a1d25ef400ea66a15b5
This commit is contained in:
Alice Kober-Sotzek
2017-07-26 11:35:42 +02:00
parent 9ac6a5f1eb
commit 1ff8a88201
2 changed files with 20 additions and 11 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.account; package com.google.gerrit.server.account;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME; import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
@@ -24,12 +25,12 @@ import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo; import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.WatchConfig.NotifyType; import com.google.gerrit.server.account.WatchConfig.NotifyType;
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey; import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
import com.google.gerrit.server.account.externalids.ExternalIds; import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.cache.CacheModule; import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.group.Groups;
import com.google.gerrit.server.index.account.AccountIndexer; import com.google.gerrit.server.index.account.AccountIndexer;
import com.google.gerrit.server.query.account.InternalAccountQuery; import com.google.gerrit.server.query.account.InternalAccountQuery;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -43,7 +44,7 @@ import com.google.inject.name.Named;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -153,6 +154,7 @@ public class AccountCacheImpl implements AccountCache {
private final SchemaFactory<ReviewDb> schema; private final SchemaFactory<ReviewDb> schema;
private final Accounts accounts; private final Accounts accounts;
private final GroupCache groupCache; private final GroupCache groupCache;
private final Groups groups;
private final GeneralPreferencesLoader loader; private final GeneralPreferencesLoader loader;
private final LoadingCache<String, Optional<Account.Id>> byName; private final LoadingCache<String, Optional<Account.Id>> byName;
private final Provider<WatchConfig.Accessor> watchConfig; private final Provider<WatchConfig.Accessor> watchConfig;
@@ -163,6 +165,7 @@ public class AccountCacheImpl implements AccountCache {
SchemaFactory<ReviewDb> sf, SchemaFactory<ReviewDb> sf,
Accounts accounts, Accounts accounts,
GroupCache groupCache, GroupCache groupCache,
Groups groups,
GeneralPreferencesLoader loader, GeneralPreferencesLoader loader,
@Named(BYUSER_NAME) LoadingCache<String, Optional<Account.Id>> byUsername, @Named(BYUSER_NAME) LoadingCache<String, Optional<Account.Id>> byUsername,
Provider<WatchConfig.Accessor> watchConfig, Provider<WatchConfig.Accessor> watchConfig,
@@ -170,6 +173,7 @@ public class AccountCacheImpl implements AccountCache {
this.accounts = accounts; this.accounts = accounts;
this.schema = sf; this.schema = sf;
this.groupCache = groupCache; this.groupCache = groupCache;
this.groups = groups;
this.loader = loader; this.loader = loader;
this.byName = byUsername; this.byName = byUsername;
this.watchConfig = watchConfig; this.watchConfig = watchConfig;
@@ -198,15 +202,13 @@ public class AccountCacheImpl implements AccountCache {
return Optional.empty(); return Optional.empty();
} }
Set<AccountGroup.UUID> internalGroups = new HashSet<>(); Set<AccountGroup.UUID> internalGroups =
for (AccountGroupMember g : db.accountGroupMembers().byAccount(who)) { groups
final AccountGroup.Id groupId = g.getAccountGroupId(); .getGroupsWithMember(db, who)
final AccountGroup group = groupCache.get(groupId); .map(groupCache::get)
if (group != null && group.getGroupUUID() != null) { .map(AccountGroup::getGroupUUID)
internalGroups.add(group.getGroupUUID()); .filter(Objects::nonNull)
} .collect(toImmutableSet());
}
internalGroups = Collections.unmodifiableSet(internalGroups);
try { try {
account.setGeneralPreferences(loader.load(who)); account.setGeneralPreferences(loader.load(who));

View File

@@ -80,4 +80,11 @@ public class Groups {
ResultSet<AccountGroupById> accountGroupByIds = db.accountGroupById().byGroup(groupId); ResultSet<AccountGroupById> accountGroupByIds = db.accountGroupById().byGroup(groupId);
return Streams.stream(accountGroupByIds).map(AccountGroupById::getIncludeUUID); return Streams.stream(accountGroupByIds).map(AccountGroupById::getIncludeUUID);
} }
public Stream<AccountGroup.Id> getGroupsWithMember(ReviewDb db, Account.Id accountId)
throws OrmException {
ResultSet<AccountGroupMember> accountGroupMembers =
db.accountGroupMembers().byAccount(accountId);
return Streams.stream(accountGroupMembers).map(AccountGroupMember::getAccountGroupId);
}
} }