Merge "AccountManager#lookup: Don't use account index to resolve external ID" into stable-2.14

This commit is contained in:
David Pursehouse
2017-11-06 13:41:23 +00:00
committed by Gerrit Code Review

View File

@@ -30,11 +30,9 @@ 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.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.query.account.InternalAccountQuery;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory; import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@@ -60,7 +58,6 @@ public class AccountManager {
private final ProjectCache projectCache; private final ProjectCache projectCache;
private final AtomicBoolean awaitsFirstAccountCheck; private final AtomicBoolean awaitsFirstAccountCheck;
private final AuditService auditService; private final AuditService auditService;
private final Provider<InternalAccountQuery> accountQueryProvider;
private final ExternalIdsUpdate.Server externalIdsUpdateFactory; private final ExternalIdsUpdate.Server externalIdsUpdateFactory;
@Inject @Inject
@@ -73,7 +70,6 @@ public class AccountManager {
ChangeUserName.Factory changeUserNameFactory, ChangeUserName.Factory changeUserNameFactory,
ProjectCache projectCache, ProjectCache projectCache,
AuditService auditService, AuditService auditService,
Provider<InternalAccountQuery> accountQueryProvider,
ExternalIdsUpdate.Server externalIdsUpdateFactory) { ExternalIdsUpdate.Server externalIdsUpdateFactory) {
this.schema = schema; this.schema = schema;
this.byIdCache = byIdCache; this.byIdCache = byIdCache;
@@ -84,17 +80,14 @@ public class AccountManager {
this.projectCache = projectCache; this.projectCache = projectCache;
this.awaitsFirstAccountCheck = new AtomicBoolean(true); this.awaitsFirstAccountCheck = new AtomicBoolean(true);
this.auditService = auditService; this.auditService = auditService;
this.accountQueryProvider = accountQueryProvider;
this.externalIdsUpdateFactory = externalIdsUpdateFactory; this.externalIdsUpdateFactory = externalIdsUpdateFactory;
} }
/** @return user identified by this external identity string */ /** @return user identified by this external identity string */
public Optional<Account.Id> lookup(String externalId) throws AccountException { public Optional<Account.Id> lookup(String externalId) throws AccountException {
try { try (ReviewDb db = schema.open()) {
AccountState accountState = accountQueryProvider.get().oneByExternalId(externalId); ExternalId extId = findExternalId(db, ExternalId.Key.parse(externalId));
return accountState != null return extId != null ? Optional.of(extId.accountId()) : Optional.empty();
? Optional.of(accountState.getAccount().getId())
: Optional.empty();
} catch (OrmException e) { } catch (OrmException e) {
throw new AccountException("Cannot lookup account " + externalId, e); throw new AccountException("Cannot lookup account " + externalId, e);
} }