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;
|
return accountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PersonIdent newIdent(Account author, Date when) {
|
protected PersonIdent newIdent(Account.Id authorId, Date when) {
|
||||||
return noteUtil.newIdent(author, when, serverIdent);
|
return noteUtil.newIdent(authorId, when, serverIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether no updates have been done. */
|
/** Whether no updates have been done. */
|
||||||
|
|||||||
@@ -129,6 +129,12 @@ public class ChangeNoteUtil {
|
|||||||
this.writeJson = config.getBoolean("notedb", "writeJson", true);
|
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
|
@VisibleForTesting
|
||||||
public PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent) {
|
public PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent) {
|
||||||
return new PersonIdent(
|
return new PersonIdent(
|
||||||
@@ -609,7 +615,7 @@ public class ChangeNoteUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendIdent(PrintWriter writer, String header, Account.Id id, Timestamp ts) {
|
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();
|
StringBuilder name = new StringBuilder();
|
||||||
PersonIdent.appendSanitized(name, ident.getName());
|
PersonIdent.appendSanitized(name, ident.getName());
|
||||||
name.append(" <");
|
name.append(" <");
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ import com.google.gerrit.reviewdb.client.RevId;
|
|||||||
import com.google.gerrit.reviewdb.client.RobotComment;
|
import com.google.gerrit.reviewdb.client.RobotComment;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
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.GerritServerConfig;
|
||||||
import com.google.gerrit.server.mail.Address;
|
import com.google.gerrit.server.mail.Address;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
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);
|
ChangeNotes notes, CurrentUser user, Date when, Comparator<String> labelNameComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final AccountCache accountCache;
|
|
||||||
private final NoteDbUpdateManager.Factory updateManagerFactory;
|
private final NoteDbUpdateManager.Factory updateManagerFactory;
|
||||||
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
||||||
private final RobotCommentUpdate.Factory robotCommentUpdateFactory;
|
private final RobotCommentUpdate.Factory robotCommentUpdateFactory;
|
||||||
@@ -168,7 +166,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
@GerritPersonIdent PersonIdent serverIdent,
|
@GerritPersonIdent PersonIdent serverIdent,
|
||||||
NotesMigration migration,
|
NotesMigration migration,
|
||||||
AccountCache accountCache,
|
|
||||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||||
@@ -181,7 +178,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
cfg,
|
cfg,
|
||||||
serverIdent,
|
serverIdent,
|
||||||
migration,
|
migration,
|
||||||
accountCache,
|
|
||||||
updateManagerFactory,
|
updateManagerFactory,
|
||||||
draftUpdateFactory,
|
draftUpdateFactory,
|
||||||
robotCommentUpdateFactory,
|
robotCommentUpdateFactory,
|
||||||
@@ -198,7 +194,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
@GerritPersonIdent PersonIdent serverIdent,
|
@GerritPersonIdent PersonIdent serverIdent,
|
||||||
NotesMigration migration,
|
NotesMigration migration,
|
||||||
AccountCache accountCache,
|
|
||||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||||
@@ -212,7 +207,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
cfg,
|
cfg,
|
||||||
serverIdent,
|
serverIdent,
|
||||||
migration,
|
migration,
|
||||||
accountCache,
|
|
||||||
updateManagerFactory,
|
updateManagerFactory,
|
||||||
draftUpdateFactory,
|
draftUpdateFactory,
|
||||||
robotCommentUpdateFactory,
|
robotCommentUpdateFactory,
|
||||||
@@ -234,7 +228,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
@GerritPersonIdent PersonIdent serverIdent,
|
@GerritPersonIdent PersonIdent serverIdent,
|
||||||
NotesMigration migration,
|
NotesMigration migration,
|
||||||
AccountCache accountCache,
|
|
||||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||||
@@ -245,7 +238,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
@Assisted Comparator<String> labelNameComparator,
|
@Assisted Comparator<String> labelNameComparator,
|
||||||
ChangeNoteUtil noteUtil) {
|
ChangeNoteUtil noteUtil) {
|
||||||
super(cfg, migration, notes, user, serverIdent, noteUtil, when);
|
super(cfg, migration, notes, user, serverIdent, noteUtil, when);
|
||||||
this.accountCache = accountCache;
|
|
||||||
this.updateManagerFactory = updateManagerFactory;
|
this.updateManagerFactory = updateManagerFactory;
|
||||||
this.draftUpdateFactory = draftUpdateFactory;
|
this.draftUpdateFactory = draftUpdateFactory;
|
||||||
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
||||||
@@ -258,7 +250,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
@GerritPersonIdent PersonIdent serverIdent,
|
@GerritPersonIdent PersonIdent serverIdent,
|
||||||
NotesMigration migration,
|
NotesMigration migration,
|
||||||
AccountCache accountCache,
|
|
||||||
NoteDbUpdateManager.Factory updateManagerFactory,
|
NoteDbUpdateManager.Factory updateManagerFactory,
|
||||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||||
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
RobotCommentUpdate.Factory robotCommentUpdateFactory,
|
||||||
@@ -281,7 +272,6 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
realAccountId,
|
realAccountId,
|
||||||
authorIdent,
|
authorIdent,
|
||||||
when);
|
when);
|
||||||
this.accountCache = accountCache;
|
|
||||||
this.draftUpdateFactory = draftUpdateFactory;
|
this.draftUpdateFactory = draftUpdateFactory;
|
||||||
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
|
||||||
this.updateManagerFactory = updateManagerFactory;
|
this.updateManagerFactory = updateManagerFactory;
|
||||||
@@ -861,8 +851,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder addIdent(StringBuilder sb, Account.Id accountId) {
|
private StringBuilder addIdent(StringBuilder sb, Account.Id accountId) {
|
||||||
Account account = accountCache.get(accountId).getAccount();
|
PersonIdent ident = newIdent(accountId, when);
|
||||||
PersonIdent ident = newIdent(account, when);
|
|
||||||
|
|
||||||
PersonIdent.appendSanitized(sb, ident.getName());
|
PersonIdent.appendSanitized(sb, ident.getName());
|
||||||
sb.append(" <");
|
sb.append(" <");
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||||
import com.google.gerrit.server.CommentsUtil;
|
import com.google.gerrit.server.CommentsUtil;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
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.GerritServerConfig;
|
||||||
import com.google.gerrit.server.config.GerritServerId;
|
import com.google.gerrit.server.config.GerritServerId;
|
||||||
import com.google.gerrit.server.notedb.ChangeBundle;
|
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);
|
static final long MAX_DELTA_MS = SECONDS.toMillis(1);
|
||||||
|
|
||||||
private final AccountCache accountCache;
|
|
||||||
private final ChangeBundleReader bundleReader;
|
private final ChangeBundleReader bundleReader;
|
||||||
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
private final ChangeDraftUpdate.Factory draftUpdateFactory;
|
||||||
private final ChangeNoteUtil changeNoteUtil;
|
private final ChangeNoteUtil changeNoteUtil;
|
||||||
@@ -132,7 +130,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
ChangeRebuilderImpl(
|
ChangeRebuilderImpl(
|
||||||
@GerritServerConfig Config cfg,
|
@GerritServerConfig Config cfg,
|
||||||
SchemaFactory<ReviewDb> schemaFactory,
|
SchemaFactory<ReviewDb> schemaFactory,
|
||||||
AccountCache accountCache,
|
|
||||||
ChangeBundleReader bundleReader,
|
ChangeBundleReader bundleReader,
|
||||||
ChangeDraftUpdate.Factory draftUpdateFactory,
|
ChangeDraftUpdate.Factory draftUpdateFactory,
|
||||||
ChangeNoteUtil changeNoteUtil,
|
ChangeNoteUtil changeNoteUtil,
|
||||||
@@ -146,7 +143,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
@Nullable ProjectCache projectCache,
|
@Nullable ProjectCache projectCache,
|
||||||
@GerritServerId String serverId) {
|
@GerritServerId String serverId) {
|
||||||
super(schemaFactory);
|
super(schemaFactory);
|
||||||
this.accountCache = accountCache;
|
|
||||||
this.bundleReader = bundleReader;
|
this.bundleReader = bundleReader;
|
||||||
this.draftUpdateFactory = draftUpdateFactory;
|
this.draftUpdateFactory = draftUpdateFactory;
|
||||||
this.changeNoteUtil = changeNoteUtil;
|
this.changeNoteUtil = changeNoteUtil;
|
||||||
@@ -551,8 +547,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
if (id == null) {
|
if (id == null) {
|
||||||
return new PersonIdent(serverIdent, events.getWhen());
|
return new PersonIdent(serverIdent, events.getWhen());
|
||||||
}
|
}
|
||||||
return changeNoteUtil.newIdent(
|
return changeNoteUtil.newIdent(id, events.getWhen(), serverIdent);
|
||||||
accountCache.get(id).getAccount(), events.getWhen(), serverIdent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HashtagsEvent> getHashtagsEvents(Change change, NoteDbUpdateManager manager)
|
private List<HashtagsEvent> getHashtagsEvents(Change change, NoteDbUpdateManager manager)
|
||||||
|
|||||||
Reference in New Issue
Block a user