Fire events with Account rather than Account.Id

In all cases, the Account.Id is only used to fetch an Account from
the AccountCache. Since the Account is already available at all call
sites, just pass that instead and avoid the cache lookup.

As a result, EventUtil#accountInfo(Account.Id) is no longer used and
it's no longer necessary for EventUtil to get AccountCache injected.

Change-Id: Ie393f194e589d1ba5fad2562d86c77d7ed088774
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
David Pursehouse
2016-10-07 10:47:18 +09:00
parent c2de51d8f6
commit 1483c87c4e
12 changed files with 17 additions and 33 deletions

View File

@@ -406,7 +406,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
* show a transition from an oldValue of 0 to the new value. * show a transition from an oldValue of 0 to the new value.
*/ */
if (fireRevisionCreated) { if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getAccountId(), revisionCreated.fire(change, patchSet, ctx.getAccount(),
ctx.getWhen(), notify); ctx.getWhen(), notify);
if (approvals != null && !approvals.isEmpty()) { if (approvals != null && !approvals.isEmpty()) {
ChangeControl changeControl = changeControlFactory.controlFor( ChangeControl changeControl = changeControlFactory.controlFor(

View File

@@ -277,7 +277,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
? NotifyHandling.ALL ? NotifyHandling.ALL
: NotifyHandling.NONE; : NotifyHandling.NONE;
if (fireRevisionCreated) { if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getAccountId(), revisionCreated.fire(change, patchSet, ctx.getAccount(),
ctx.getWhen(), notify); ctx.getWhen(), notify);
} }
} }

View File

@@ -223,7 +223,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
@Override @Override
public void postUpdate(Context ctx) throws OrmException { public void postUpdate(Context ctx) throws OrmException {
draftPublished.fire(change, patchSet, ctx.getAccountId(), draftPublished.fire(change, patchSet, ctx.getAccount(),
ctx.getWhen()); ctx.getWhen());
if (patchSet.isDraft() && change.getStatus() == Change.Status.DRAFT) { if (patchSet.isDraft() && change.getStatus() == Change.Status.DRAFT) {
// Skip emails if the patch set is still a draft. // Skip emails if the patch set is still a draft.

View File

@@ -166,7 +166,7 @@ public class SetHashtagsOp extends BatchUpdate.Op {
@Override @Override
public void postUpdate(Context ctx) throws OrmException { public void postUpdate(Context ctx) throws OrmException {
if (updated() && fireEvent) { if (updated() && fireEvent) {
hashtagsEdited.fire(change, ctx.getAccountId(), updatedHashtags, hashtagsEdited.fire(change, ctx.getAccount(), updatedHashtags,
toAdd, toRemove, ctx.getWhen()); toAdd, toRemove, ctx.getWhen());
} }
} }

View File

@@ -60,7 +60,7 @@ public class DraftPublished {
} }
} }
public void fire(Change change, PatchSet patchSet, Account.Id accountId, public void fire(Change change, PatchSet patchSet, Account accountId,
Timestamp when) { Timestamp when) {
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GpgException; import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.change.ChangeJson; import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
@@ -47,18 +46,15 @@ public class EventUtil {
private final ChangeData.Factory changeDataFactory; private final ChangeData.Factory changeDataFactory;
private final Provider<ReviewDb> db; private final Provider<ReviewDb> db;
private final ChangeJson changeJson; private final ChangeJson changeJson;
private final AccountCache accountCache;
@Inject @Inject
EventUtil(ChangeJson.Factory changeJsonFactory, EventUtil(ChangeJson.Factory changeJsonFactory,
ChangeData.Factory changeDataFactory, ChangeData.Factory changeDataFactory,
Provider<ReviewDb> db, Provider<ReviewDb> db) {
AccountCache accountCache) {
this.changeDataFactory = changeDataFactory; this.changeDataFactory = changeDataFactory;
this.db = db; this.db = db;
this.changeJson = changeJsonFactory.create( this.changeJson = changeJsonFactory.create(
EnumSet.allOf(ListChangesOption.class)); EnumSet.allOf(ListChangesOption.class));
this.accountCache = accountCache;
} }
public ChangeInfo changeInfo(Change change) throws OrmException { public ChangeInfo changeInfo(Change change) throws OrmException {
@@ -91,10 +87,6 @@ public class EventUtil {
return ai; return ai;
} }
public AccountInfo accountInfo(Account.Id accountId) {
return accountInfo(accountCache.get(accountId).getAccount());
}
public Map<String, ApprovalInfo> approvals(Account a, public Map<String, ApprovalInfo> approvals(Account a,
Map<String, Short> approvals, Timestamp ts) { Map<String, Short> approvals, Timestamp ts) {
Map<String, ApprovalInfo> result = new HashMap<>(); Map<String, ApprovalInfo> result = new HashMap<>();

View File

@@ -38,10 +38,6 @@ public class GitReferenceUpdated {
public void fire(Project.NameKey project, RefUpdate refUpdate, public void fire(Project.NameKey project, RefUpdate refUpdate,
ReceiveCommand.Type type, Account updater) {} ReceiveCommand.Type type, Account updater) {}
@Override
public void fire(Project.NameKey project, RefUpdate refUpdate,
ReceiveCommand.Type type, Account.Id updater) {}
@Override @Override
public void fire(Project.NameKey project, RefUpdate refUpdate, public void fire(Project.NameKey project, RefUpdate refUpdate,
Account updater) {} Account updater) {}
@@ -60,7 +56,7 @@ public class GitReferenceUpdated {
@Override @Override
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate,
Account.Id updater) {} Account updater) {}
}; };
private final DynamicSet<GitReferenceUpdatedListener> listeners; private final DynamicSet<GitReferenceUpdatedListener> listeners;
@@ -84,12 +80,6 @@ public class GitReferenceUpdated {
refUpdate.getNewObjectId(), type, util.accountInfo(updater)); refUpdate.getNewObjectId(), type, util.accountInfo(updater));
} }
public void fire(Project.NameKey project, RefUpdate refUpdate,
ReceiveCommand.Type type, Account.Id updater) {
fire(project, refUpdate.getName(), refUpdate.getOldObjectId(),
refUpdate.getNewObjectId(), type, util.accountInfo(updater));
}
public void fire(Project.NameKey project, RefUpdate refUpdate, public void fire(Project.NameKey project, RefUpdate refUpdate,
Account updater) { Account updater) {
fire(project, refUpdate.getName(), refUpdate.getOldObjectId(), fire(project, refUpdate.getName(), refUpdate.getOldObjectId(),
@@ -115,7 +105,7 @@ public class GitReferenceUpdated {
} }
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate,
Account.Id updater) { Account updater) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }

View File

@@ -20,7 +20,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.HashtagsEditedListener; import com.google.gerrit.extensions.events.HashtagsEditedListener;
import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account.Id; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -59,7 +59,7 @@ public class HashtagsEdited {
} }
} }
public void fire(Change change, Id accountId, public void fire(Change change, Account account,
ImmutableSortedSet<String> hashtags, Set<String> added, ImmutableSortedSet<String> hashtags, Set<String> added,
Set<String> removed, Timestamp when) { Set<String> removed, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
@@ -67,7 +67,7 @@ public class HashtagsEdited {
} }
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.accountInfo(accountId), util.accountInfo(account),
hashtags, added, removed, hashtags, added, removed,
when); when);
} catch (OrmException e) { } catch (OrmException e) {

View File

@@ -60,7 +60,7 @@ public class RevisionCreated {
} }
} }
public void fire(Change change, PatchSet patchSet, Account.Id uploader, public void fire(Change change, PatchSet patchSet, Account uploader,
Timestamp when, NotifyHandling notify) { Timestamp when, NotifyHandling notify) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;

View File

@@ -442,7 +442,9 @@ public class BatchUpdate implements AutoCloseable {
u.gitRefUpdated.fire( u.gitRefUpdated.fire(
u.project, u.project,
u.batchRefUpdate, u.batchRefUpdate,
u.getUser().isIdentifiedUser() ? u.getUser().getAccountId() : null); u.getUser().isIdentifiedUser()
? u.getUser().asIdentifiedUser().getAccount()
: null);
} }
} }

View File

@@ -407,7 +407,7 @@ public class ReplaceOp extends BatchUpdate.Op {
NotifyHandling notify = magicBranch != null && magicBranch.notify != null NotifyHandling notify = magicBranch != null && magicBranch.notify != null
? magicBranch.notify ? magicBranch.notify
: NotifyHandling.ALL; : NotifyHandling.ALL;
revisionCreated.fire(change, newPatchSet, ctx.getAccountId(), revisionCreated.fire(change, newPatchSet, ctx.getAccount(),
ctx.getWhen(), notify); ctx.getWhen(), notify);
try { try {
fireCommentAddedEvent(ctx); fireCommentAddedEvent(ctx);

View File

@@ -355,7 +355,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
switch (result) { switch (result) {
case NEW: case NEW:
referenceUpdated.fire(project, ru, ReceiveCommand.Type.CREATE, referenceUpdated.fire(project, ru, ReceiveCommand.Type.CREATE,
identifiedUser.get().getAccountId()); identifiedUser.get().getAccount());
break; break;
case FAST_FORWARD: case FAST_FORWARD:
case FORCED: case FORCED: