Merge "InternalChangeQuery: Load changes from notedb if enabled"

This commit is contained in:
Edwin Kempin
2016-02-12 10:57:48 +00:00
committed by Gerrit Code Review

View File

@@ -35,6 +35,8 @@ import com.google.gerrit.server.index.ChangeIndex;
import com.google.gerrit.server.index.IndexCollection; import com.google.gerrit.server.index.IndexCollection;
import com.google.gerrit.server.index.IndexConfig; import com.google.gerrit.server.index.IndexConfig;
import com.google.gerrit.server.index.Schema; import com.google.gerrit.server.index.Schema;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -84,16 +86,22 @@ public class InternalChangeQuery {
private final QueryProcessor qp; private final QueryProcessor qp;
private final IndexCollection indexes; private final IndexCollection indexes;
private final ChangeData.Factory changeDataFactory; private final ChangeData.Factory changeDataFactory;
private final NotesMigration notesMigration;
private final ChangeNotes.Factory notesFactory;
@Inject @Inject
InternalChangeQuery(IndexConfig indexConfig, InternalChangeQuery(IndexConfig indexConfig,
QueryProcessor queryProcessor, QueryProcessor queryProcessor,
IndexCollection indexes, IndexCollection indexes,
ChangeData.Factory changeDataFactory) { ChangeData.Factory changeDataFactory,
NotesMigration notesMigration,
ChangeNotes.Factory notesFactory) {
this.indexConfig = indexConfig; this.indexConfig = indexConfig;
qp = queryProcessor.enforceVisibility(false); qp = queryProcessor.enforceVisibility(false);
this.indexes = indexes; this.indexes = indexes;
this.changeDataFactory = changeDataFactory; this.changeDataFactory = changeDataFactory;
this.notesMigration = notesMigration;
this.notesFactory = notesFactory;
} }
public InternalChangeQuery setLimit(int n) { public InternalChangeQuery setLimit(int n) {
@@ -199,6 +207,18 @@ public class InternalChangeQuery {
} }
List<ChangeData> cds = new ArrayList<>(hashes.size()); List<ChangeData> cds = new ArrayList<>(hashes.size());
if (notesMigration.enabled()) {
for (Change.Id cid : changeIds) {
Change c =
notesFactory.create(db, branch.getParentKey(), cid).getChange();
if (c != null && c.getDest().equals(branch)
&& c.getStatus() != Change.Status.MERGED) {
cds.add(changeDataFactory.create(db, c));
}
}
return cds;
}
for (Change c : db.changes().get(changeIds)) { for (Change c : db.changes().get(changeIds)) {
if (c.getDest().equals(branch) && c.getStatus() != Change.Status.MERGED) { if (c.getDest().equals(branch) && c.getStatus() != Change.Status.MERGED) {
cds.add(changeDataFactory.create(db, c)); cds.add(changeDataFactory.create(db, c));