Skip to content

Commit 11de246

Browse files
committed
chore(index): use real-time scrolling instead of scroll API...
...when creating compare between two branches
1 parent 9f50aeb commit 11de246

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

commons/com.b2international.index/src/com/b2international/index/revision/DefaultRevisionIndex.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.b2international.index.query.Expressions;
3333
import com.b2international.index.query.Expressions.ExpressionBuilder;
3434
import com.b2international.index.query.Query;
35+
import com.b2international.index.query.Query.AfterWhereBuilder;
3536
import com.b2international.index.query.SortBy;
3637
import com.b2international.index.query.SortBy.Order;
3738
import com.b2international.index.revision.RevisionCompare.Builder;
@@ -189,13 +190,22 @@ private void doRevisionCompare(Searcher searcher, RevisionBranchRef compareRef,
189190
.build());
190191
}
191192

192-
// apply commits happened on the compareRef segments in chronological order
193-
searcher.scroll(Query.select(Commit.class)
194-
.where(compareCommitsQuery.build())
195-
.limit(20) // load only 20 commits for each batch (import commits tend to be large, so if we load 20 of them we should not use that much memory)
196-
.sortBy(SortBy.field(Commit.Fields.TIMESTAMP, Order.ASC))
197-
.build())
198-
.forEach(commits -> commits.forEach(result::apply));
193+
// apply commits happened on the compareRef segments in chronological order
194+
AfterWhereBuilder<Commit> query = Query.select(Commit.class)
195+
.where(compareCommitsQuery.build())
196+
.limit(20) // load only 20 commits for each batch (import commits tend to be large, so if we load 20 of them we should not use that much memory)
197+
.sortBy(SortBy.field(Commit.Fields.TIMESTAMP, Order.ASC));
198+
199+
int processedCommits = 0;
200+
Hits<Commit> hits = null;
201+
do {
202+
if (hits != null) {
203+
query.searchAfter(hits.getSearchAfter());
204+
}
205+
hits = searcher.search(query.build());
206+
hits.forEach(result::apply);
207+
processedCommits += hits.getLimit();
208+
} while (processedCommits < hits.getTotal());
199209
}
200210

201211
private String getBranchPath(Searcher searcher, long branchId) throws IOException {

0 commit comments

Comments
 (0)