Add a method to query accounts only by their external ID's email

And use this method from the Prolog predicates, in order to remove the
dependency on the index when indexing rules. This fixes the two
remaining tests in RulesIT.

The newly introduced method doesn't query the index to find accounts
by their preferred email. Instead, the external IDs cache is assumed to
be consistent with reality. This method is used in PatchSetInfoFactory
and EventFactory to allow usage of these two classes from an environment
with no index access.

The underlying issue (accounts with no external IDs) is already fixed,
and this change is a first step towards removing the patches required by
it.

Change-Id: I93a91c11f6473dfe9e4d9b56c27a351234b50e56
This commit is contained in:
Maxime Guerreiro
2018-06-27 13:13:19 +00:00
parent 20282d6879
commit 7deacf1f1f
3 changed files with 14 additions and 9 deletions

View File

@@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.rules.PrologEnvironment;
import com.google.gwtorm.server.OrmException;
import com.googlecode.prolog_cafe.exceptions.PrologException;
import com.googlecode.prolog_cafe.exceptions.SystemException;
import com.googlecode.prolog_cafe.lang.IntegerTerm;
@@ -56,11 +55,11 @@ abstract class AbstractCommitUserIdentityPredicate extends Predicate.P3 {
Emails emails = env.getArgs().getEmails();
Account.Id id = null;
try {
ImmutableSet<Account.Id> ids = emails.getAccountFor(userId.getEmailAddress());
ImmutableSet<Account.Id> ids = emails.getAccountForExternal(userId.getEmailAddress());
if (ids.size() == 1) {
id = ids.iterator().next();
}
} catch (IOException | OrmException e) {
} catch (IOException e) {
throw new SystemException(e.getMessage());
}