|
32 | 32 | import com.b2international.index.query.Expressions;
|
33 | 33 | import com.b2international.index.query.Expressions.ExpressionBuilder;
|
34 | 34 | import com.b2international.index.query.Query;
|
| 35 | +import com.b2international.index.query.Query.AfterWhereBuilder; |
35 | 36 | import com.b2international.index.query.SortBy;
|
36 | 37 | import com.b2international.index.query.SortBy.Order;
|
37 | 38 | import com.b2international.index.revision.RevisionCompare.Builder;
|
@@ -189,13 +190,22 @@ private void doRevisionCompare(Searcher searcher, RevisionBranchRef compareRef,
|
189 | 190 | .build());
|
190 | 191 | }
|
191 | 192 |
|
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()); |
199 | 209 | }
|
200 | 210 |
|
201 | 211 | private String getBranchPath(Searcher searcher, long branchId) throws IOException {
|
|
0 commit comments