Move change batch loading from InternalChangeQuery to ChangeNotes.Factory
All remaining code that loads changes in batches from the database should go into ChangeNotes.Factory. Change-Id: Ia0d1434a6e0e33417c8487a040af25ea1f932cb4 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
b72fcc55ed
commit
eec1c4856d
@ -73,6 +73,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -230,6 +231,31 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
change.getProject(), change).load();
|
||||
}
|
||||
|
||||
public List<ChangeNotes> create(ReviewDb db, Project.NameKey project,
|
||||
Collection<Change.Id> changeIds, Predicate<ChangeNotes> predicate)
|
||||
throws OrmException {
|
||||
List<ChangeNotes> notes = new ArrayList<>();
|
||||
if (migration.enabled()) {
|
||||
for (Change.Id cid : changeIds) {
|
||||
ChangeNotes cn = create(db, project, cid);
|
||||
if (cn.getChange() != null && predicate.apply(cn)) {
|
||||
notes.add(cn);
|
||||
}
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
|
||||
for (Change c : db.changes().get(changeIds)) {
|
||||
if (c != null && project.equals(c.getDest().getParentKey())) {
|
||||
ChangeNotes cn = createFromChangeOnlyWhenNotedbDisabled(c);
|
||||
if (predicate.apply(cn)) {
|
||||
notes.add(cn);
|
||||
}
|
||||
}
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
|
||||
public ListMultimap<Project.NameKey, ChangeNotes> create(ReviewDb db,
|
||||
Predicate<ChangeNotes> predicate) throws IOException, OrmException {
|
||||
ListMultimap<Project.NameKey, ChangeNotes> m = ArrayListMultimap.create();
|
||||
|
@ -22,8 +22,10 @@ import static com.google.gerrit.server.query.Predicate.or;
|
||||
import static com.google.gerrit.server.query.change.ChangeStatusPredicate.open;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
@ -36,7 +38,6 @@ import com.google.gerrit.server.index.IndexCollection;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
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.QueryParseException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@ -86,7 +87,6 @@ public class InternalChangeQuery {
|
||||
private final QueryProcessor qp;
|
||||
private final IndexCollection indexes;
|
||||
private final ChangeData.Factory changeDataFactory;
|
||||
private final NotesMigration notesMigration;
|
||||
private final ChangeNotes.Factory notesFactory;
|
||||
|
||||
@Inject
|
||||
@ -94,13 +94,11 @@ public class InternalChangeQuery {
|
||||
QueryProcessor queryProcessor,
|
||||
IndexCollection indexes,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
NotesMigration notesMigration,
|
||||
ChangeNotes.Factory notesFactory) {
|
||||
this.indexConfig = indexConfig;
|
||||
qp = queryProcessor.enforceVisibility(false);
|
||||
this.indexes = indexes;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
this.notesMigration = notesMigration;
|
||||
this.notesFactory = notesFactory;
|
||||
}
|
||||
|
||||
@ -186,8 +184,8 @@ public class InternalChangeQuery {
|
||||
}
|
||||
|
||||
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromDatabase(
|
||||
Repository repo, ReviewDb db, Branch.NameKey branch, List<String> hashes)
|
||||
throws OrmException, IOException {
|
||||
Repository repo, final ReviewDb db, final Branch.NameKey branch,
|
||||
List<String> hashes) throws OrmException, IOException {
|
||||
Set<Change.Id> changeIds = Sets.newHashSetWithExpectedSize(hashes.size());
|
||||
String lastPrefix = null;
|
||||
for (Ref ref :
|
||||
@ -206,25 +204,20 @@ public class InternalChangeQuery {
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
if (c.getDest().equals(branch) && c.getStatus() != Change.Status.MERGED) {
|
||||
cds.add(changeDataFactory.create(db, c));
|
||||
}
|
||||
}
|
||||
return cds;
|
||||
return Lists.transform(notesFactory.create(db, branch.getParentKey(),
|
||||
changeIds, new com.google.common.base.Predicate<ChangeNotes>() {
|
||||
@Override
|
||||
public boolean apply(ChangeNotes notes) {
|
||||
Change c = notes.getChange();
|
||||
return c.getDest().equals(branch)
|
||||
&& c.getStatus() != Change.Status.MERGED;
|
||||
}
|
||||
}), new Function<ChangeNotes, ChangeData>() {
|
||||
@Override
|
||||
public ChangeData apply(ChangeNotes notes) {
|
||||
return changeDataFactory.create(db, notes.getChange());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromIndex(
|
||||
|
Loading…
Reference in New Issue
Block a user