Stop passing ReviewDb, etc. to ChangeData methods
Many methods that are intended for lazy initialization take a ReviewDb, and some take other helper objects such as GitRepositoryManager. This achieves the intended lazy-loading behavior but requires a lot of injection of dependencies into callers, and may become untenable as lazy loading of ChangeData requires more helpers. Instead, since after all this is Java, construct ChangeData with a Factory. This is subtle because it is used from a lot of places that need control over which ReviewDb handle to pass in, so the factory methods still need to take a db. ChangeData objects are still intended (i.e. safe) for use only by one thread, so having a single ReviewDb instance stored for the lifetime of the ChangeData should be fine. We just need to be careful about which we pass in, particularly in a place like ChangeIndexer. As a side effect, clean up some other injection, particularly in the predicate class hierarchy. Change-Id: I52e1eb2a76788c12dd95767e89095ab80df7e1cc
This commit is contained in:
@@ -43,14 +43,17 @@ import java.util.TreeMap;
|
||||
|
||||
public class ReviewerJson {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ChangeData.Factory changeDataFactory;
|
||||
private final LabelNormalizer labelNormalizer;
|
||||
private final AccountInfo.Loader.Factory accountLoaderFactory;
|
||||
|
||||
@Inject
|
||||
ReviewerJson(Provider<ReviewDb> db,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
LabelNormalizer labelNormalizer,
|
||||
AccountInfo.Loader.Factory accountLoaderFactory) {
|
||||
this.db = db;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
this.labelNormalizer = labelNormalizer;
|
||||
this.accountLoaderFactory = accountLoaderFactory;
|
||||
}
|
||||
@@ -98,8 +101,8 @@ public class ReviewerJson {
|
||||
|
||||
// Add dummy approvals for all permitted labels for the user even if they
|
||||
// do not exist in the DB.
|
||||
ChangeData cd = new ChangeData(ctl);
|
||||
PatchSet ps = cd.currentPatchSet(db);
|
||||
ChangeData cd = changeDataFactory.create(db.get(), ctl);
|
||||
PatchSet ps = cd.currentPatchSet();
|
||||
if (ps != null) {
|
||||
for (SubmitRecord rec :
|
||||
ctl.canSubmit(db.get(), ps, cd, true, false, true)) {
|
||||
|
Reference in New Issue
Block a user