Add cache for external ids
Introducing a cache for external ids is a preparation step for moving the external ids from ReviewDb into NoteDb. For NoteDb it is planned to store the external ids in a git note branch, where the note keys are the sha1's of the external ids and the note values contain the external id, the account id and optionally email and password. With this format we can easily lookup external ids by the external id, but listing all external ids of an account requires parsing all external ids. Looking up the external ids of an account is possible from the account index, however for reindexing an account we would still need to lookup all external ids of the account from git. Having a cache for the external ids ensures that the external ids are only loaded once from git. If there is any update to external ids, we take care to update the cache as well. For this change it means that all code that modifies external ids must do an extra call to update the external id cache. This is not optimal since updating the cache can be easily forgotten. This is why the follow-up change cleans this up by introducing a dedicated class that handles all external id updates and then this is the only class that must take care to update the external id cache. Change-Id: I9ea979c646cddb9b39e723de5c061a70a2ce6fd6 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -18,6 +18,8 @@ import com.google.gerrit.extensions.client.AuthType;
|
||||
import com.google.gwtorm.client.Column;
|
||||
import com.google.gwtorm.client.StringKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Association of an external account identifier to a local {@link Account}. */
|
||||
public final class AccountExternalId {
|
||||
/**
|
||||
@@ -167,4 +169,21 @@ public final class AccountExternalId {
|
||||
public void setCanDelete(final boolean t) {
|
||||
canDelete = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AccountExternalId) {
|
||||
AccountExternalId extId = (AccountExternalId) o;
|
||||
return Objects.equals(key, extId.key)
|
||||
&& Objects.equals(accountId, extId.accountId)
|
||||
&& Objects.equals(emailAddress, extId.emailAddress)
|
||||
&& Objects.equals(password, extId.password);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key, accountId, emailAddress, password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.reviewdb.server;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||
import com.google.gwtorm.server.Access;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -28,9 +27,6 @@ public interface AccountExternalIdAccess extends
|
||||
@PrimaryKey("key")
|
||||
AccountExternalId get(AccountExternalId.Key key) throws OrmException;
|
||||
|
||||
@Query("WHERE accountId = ?")
|
||||
ResultSet<AccountExternalId> byAccount(Account.Id id) throws OrmException;
|
||||
|
||||
@Query
|
||||
ResultSet<AccountExternalId> all() throws OrmException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user