ChangeNoteUtil: Support PersonIdent creation by account ID
Some callers only have an account ID available. Instead of letting each caller lookup the account from the account cache, just accept an account ID for the PersonIdent creation and do the account cache access only in this one place. Change-Id: I9369c39ff2ab24984483285f80477ddc04b800fe Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -174,8 +174,8 @@ public abstract class AbstractChangeUpdate {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
protected PersonIdent newIdent(Account author, Date when) {
|
||||
return noteUtil.newIdent(author, when, serverIdent);
|
||||
protected PersonIdent newIdent(Account.Id authorId, Date when) {
|
||||
return noteUtil.newIdent(authorId, when, serverIdent);
|
||||
}
|
||||
|
||||
/** Whether no updates have been done. */
|
||||
|
||||
@@ -129,6 +129,12 @@ public class ChangeNoteUtil {
|
||||
this.writeJson = config.getBoolean("notedb", "writeJson", true);
|
||||
}
|
||||
|
||||
public PersonIdent newIdent(Account.Id authorId, Date when, PersonIdent serverIdent) {
|
||||
Account author = accountCache.get(authorId).getAccount();
|
||||
return new PersonIdent(
|
||||
author.getName(), author.getId().get() + "@" + serverId, when, serverIdent.getTimeZone());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent) {
|
||||
return new PersonIdent(
|
||||
@@ -609,7 +615,7 @@ public class ChangeNoteUtil {
|
||||
}
|
||||
|
||||
private void appendIdent(PrintWriter writer, String header, Account.Id id, Timestamp ts) {
|
||||
PersonIdent ident = newIdent(accountCache.get(id).getAccount(), ts, serverIdent);
|
||||
PersonIdent ident = newIdent(id, ts, serverIdent);
|
||||
StringBuilder name = new StringBuilder();
|
||||
PersonIdent.appendSanitized(name, ident.getName());
|
||||
name.append(" <");
|
||||
|
||||
@@ -61,7 +61,6 @@ import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.client.RobotComment;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -124,7 +123,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
ChangeNotes notes, CurrentUser user, Date when, Comparator<String> labelNameComparator);
|
||||
}
|
||||
|
||||
private final AccountCache accountCache;
|
||||
private final NoteDbUpdateManager.Factory updateManagerFactory;
|
||||
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
||||
private final RobotCommentUpdate.Factory robotCommentUpdateFactory;
|
||||
@@ -168,7 +166,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
@GerritServerConfig Config cfg,
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
NotesMigration migration,
|
||||
AccountCache accountCache,
|
||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||
@@ -181,7 +178,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
cfg,
|
||||
serverIdent,
|
||||
migration,
|
||||
accountCache,
|
||||
updateManagerFactory,
|
||||
draftUpdateFactory,
|
||||
robotCommentUpdateFactory,
|
||||
@@ -198,7 +194,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
@GerritServerConfig Config cfg,
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
NotesMigration migration,
|
||||
AccountCache accountCache,
|
||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||
@@ -212,7 +207,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
cfg,
|
||||
serverIdent,
|
||||
migration,
|
||||
accountCache,
|
||||
updateManagerFactory,
|
||||
draftUpdateFactory,
|
||||
robotCommentUpdateFactory,
|
||||
@@ -234,7 +228,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
@GerritServerConfig Config cfg,
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
NotesMigration migration,
|
||||
AccountCache accountCache,
|
||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||
@@ -245,7 +238,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
@Assisted Comparator<String> labelNameComparator,
|
||||
ChangeNoteUtil noteUtil) {
|
||||
super(cfg, migration, notes, user, serverIdent, noteUtil, when);
|
||||
this.accountCache = accountCache;
|
||||
this.updateManagerFactory = updateManagerFactory;
|
||||
this.draftUpdateFactory = draftUpdateFactory;
|
||||
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
||||
@@ -258,7 +250,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
@GerritServerConfig Config cfg,
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
NotesMigration migration,
|
||||
AccountCache accountCache,
|
||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||
@@ -281,7 +272,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
realAccountId,
|
||||
authorIdent,
|
||||
when);
|
||||
this.accountCache = accountCache;
|
||||
this.draftUpdateFactory = draftUpdateFactory;
|
||||
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
||||
this.updateManagerFactory = updateManagerFactory;
|
||||
@@ -861,8 +851,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
}
|
||||
|
||||
private StringBuilder addIdent(StringBuilder sb, Account.Id accountId) {
|
||||
Account account = accountCache.get(accountId).getAccount();
|
||||
PersonIdent ident = newIdent(account, when);
|
||||
PersonIdent ident = newIdent(accountId, when);
|
||||
|
||||
PersonIdent.appendSanitized(sb, ident.getName());
|
||||
sb.append(" <");
|
||||
|
||||
@@ -49,7 +49,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.CommentsUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.GerritServerId;
|
||||
import com.google.gerrit.server.notedb.ChangeBundle;
|
||||
@@ -113,7 +112,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
||||
*/
|
||||
static final long MAX_DELTA_MS = SECONDS.toMillis(1);
|
||||
|
||||
private final AccountCache accountCache;
|
||||
private final ChangeBundleReader bundleReader;
|
||||
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
||||
private final ChangeNoteUtil changeNoteUtil;
|
||||
@@ -132,7 +130,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
||||
ChangeRebuilderImpl(
|
||||
@GerritServerConfig Config cfg,
|
||||
SchemaFactory<ReviewDb> schemaFactory,
|
||||
AccountCache accountCache,
|
||||
ChangeBundleReader bundleReader,
|
||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||
ChangeNoteUtil changeNoteUtil,
|
||||
@@ -146,7 +143,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
||||
@Nullable ProjectCache projectCache,
|
||||
@GerritServerId String serverId) {
|
||||
super(schemaFactory);
|
||||
this.accountCache = accountCache;
|
||||
this.bundleReader = bundleReader;
|
||||
this.draftUpdateFactory = draftUpdateFactory;
|
||||
this.changeNoteUtil = changeNoteUtil;
|
||||
@@ -551,8 +547,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
||||
if (id == null) {
|
||||
return new PersonIdent(serverIdent, events.getWhen());
|
||||
}
|
||||
return changeNoteUtil.newIdent(
|
||||
accountCache.get(id).getAccount(), events.getWhen(), serverIdent);
|
||||
return changeNoteUtil.newIdent(id, events.getWhen(), serverIdent);
|
||||
}
|
||||
|
||||
private List<HashtagsEvent> getHashtagsEvents(Change change, NoteDbUpdateManager manager)
|
||||
|
||||
Reference in New Issue
Block a user