Require account index and remove fallbacks

The account data is moved from ReviewDb into git.

Change-Id: I643827179b24601b138f394cfff5890f919b9da9
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-07-07 10:40:15 +02:00
parent 9b52b4502e
commit 10aa4e2bbf
16 changed files with 77 additions and 468 deletions

View File

@@ -17,9 +17,7 @@ package com.google.gerrit.server.account;
import static java.util.stream.Collectors.toSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountExternalId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.index.account.AccountIndexCollection;
import com.google.gerrit.server.query.account.InternalAccountQuery;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@@ -38,19 +36,16 @@ public class AccountResolver {
private final Realm realm;
private final AccountByEmailCache byEmail;
private final AccountCache byId;
private final AccountIndexCollection accountIndexes;
private final Provider<InternalAccountQuery> accountQueryProvider;
@Inject
AccountResolver(Realm realm,
AccountByEmailCache byEmail,
AccountCache byId,
AccountIndexCollection accountIndexes,
Provider<InternalAccountQuery> accountQueryProvider) {
this.realm = realm;
this.byEmail = byEmail;
this.byId = byId;
this.accountIndexes = accountIndexes;
this.accountQueryProvider = accountQueryProvider;
}
@@ -183,42 +178,15 @@ public class AccountResolver {
return Collections.singleton(id);
}
if (accountIndexes.getSearchIndex() != null) {
List<AccountState> m = accountQueryProvider.get().byFullName(nameOrEmail);
if (m.size() == 1) {
return Collections.singleton(m.get(0).getAccount().getId());
}
// At this point we have no clue. Just perform a whole bunch of suggestions
// and pray we come up with a reasonable result list.
return accountQueryProvider.get().byDefault(nameOrEmail).stream()
.map(a -> a.getAccount().getId())
.collect(toSet());
}
List<Account> m = db.accounts().byFullName(nameOrEmail).toList();
List<AccountState> m = accountQueryProvider.get().byFullName(nameOrEmail);
if (m.size() == 1) {
return Collections.singleton(m.get(0).getId());
return Collections.singleton(m.get(0).getAccount().getId());
}
// At this point we have no clue. Just perform a whole bunch of suggestions
// and pray we come up with a reasonable result list.
Set<Account.Id> result = new HashSet<>();
String a = nameOrEmail;
String b = nameOrEmail + "\u9fa5";
for (Account act : db.accounts().suggestByFullName(a, b, 10)) {
result.add(act.getId());
}
for (AccountExternalId extId : db.accountExternalIds()
.suggestByKey(
new AccountExternalId.Key(AccountExternalId.SCHEME_USERNAME, a),
new AccountExternalId.Key(AccountExternalId.SCHEME_USERNAME, b), 10)) {
result.add(extId.getAccountId());
}
for (AccountExternalId extId : db.accountExternalIds()
.suggestByEmailAddress(a, b, 10)) {
result.add(extId.getAccountId());
}
return result;
return accountQueryProvider.get().byDefault(nameOrEmail).stream()
.map(a -> a.getAccount().getId())
.collect(toSet());
}
}