Always load change notes when they are created
This is a preparation for when reviewdb is gone and changes are fully initialised from notedb. Then we will instantiate the Change object only in ChangeNotes#onLoad, and no longer in ChangeNotes.Factory#create. This is because the Change can only be instantiated after parsing the notes branch. The problem is that lots of callers access the Change object by ChangeNotes#getChange() before invoking ChangeNotes#load() in which case the change would not be available yet. Instead of adapting all callers to invoke ChangeNotes#load() before asking for the change, make sure that the change notes are always loaded on creation. Change notes are still not loaded eagerly when they are created from an indexed change. This is because we don't want to access notedb during a query (similar to how we don't want to access the database during a query). Change-Id: Id654f192910e131d695e5ba0d60daf18bf736ded Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -635,9 +635,6 @@ public class BatchUpdate implements AutoCloseable {
|
||||
ChangeNotes notes = changeNotesFactory.createForNew(c);
|
||||
ChangeContext ctx = new ChangeContext(
|
||||
changeControlFactory.controlFor(notes, user), new BatchUpdateReviewDb(db));
|
||||
if (notesMigration.readChanges()) {
|
||||
ctx.getNotes().load();
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
// TODO: Throw NoSuchChangeException when the change is not found in the
|
||||
// database
|
||||
return new ChangeNotes(repoManager, migration, allUsersProvider, project,
|
||||
change);
|
||||
change).load();
|
||||
}
|
||||
|
||||
public ChangeNotes createFromIndexedChange(Change change) {
|
||||
@@ -130,9 +130,9 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
change.getProject(), change);
|
||||
}
|
||||
|
||||
public ChangeNotes createForNew(Change change) {
|
||||
public ChangeNotes createForNew(Change change) throws OrmException {
|
||||
return new ChangeNotes(repoManager, migration, allUsersProvider,
|
||||
change.getProject(), change);
|
||||
change.getProject(), change).load();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user