Cache IdentifiedUser across PrologEnvironments

When running multiple rules for the same change, the set of
reviewers is identical as ChangeControl goes up the project
tree and runs rules in parent projects. Recycle all of the
IdentifiedUser objects that were made in one invocation for
the next one, to avoid looking them up again in AccountCache.

Change-Id: I4031a3f8f9eb0328f0abbbfce1f38eb67b4877d3
This commit is contained in:
Shawn O. Pearce
2012-05-02 14:38:05 -07:00
parent c65ff855af
commit 4502dfbde0
2 changed files with 43 additions and 53 deletions

View File

@@ -16,12 +16,16 @@ package com.google.gerrit.rules;
import static com.google.gerrit.rules.StoredValue.create;
import com.google.common.collect.Maps;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetInfo;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListCache;
@@ -38,6 +42,8 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import java.util.Map;
public final class StoredValues {
public static final StoredValue<ReviewDb> REVIEW_DB = create(ReviewDb.class);
public static final StoredValue<Change> CHANGE = create(Change.class);
@@ -105,6 +111,23 @@ public final class StoredValues {
}
};
public static final StoredValue<AnonymousUser> ANONYMOUS_USER =
new StoredValue<AnonymousUser>() {
@Override
protected AnonymousUser createValue(Prolog engine) {
PrologEnvironment env = (PrologEnvironment) engine.control;
return env.getInjector().getInstance(AnonymousUser.class);
}
};
public static final StoredValue<Map<Account.Id, IdentifiedUser>> USERS =
new StoredValue<Map<Account.Id, IdentifiedUser>>() {
@Override
protected Map<Account.Id, IdentifiedUser> createValue(Prolog engine) {
return Maps.newHashMap();
}
};
private StoredValues() {
}
}