summaryrefslogtreecommitdiffstats
path: root/java/com/google/gerrit/index/query/PaginatingSource.java
diff options
context:
space:
mode:
authorDiego Zambelli Sessona <diego.sessona@gmail.com>2024-04-04 12:58:27 +0200
committerDiego Zambelli Sessona <diego.sessona@gmail.com>2024-04-04 13:03:09 +0200
commita5a51a94cc2df3a1cebcd9a98f4edd53c834adb9 (patch)
tree962d79ce17442d0d04004232ed05e45dd1dfd9d6 /java/com/google/gerrit/index/query/PaginatingSource.java
parent27847d3bbf4fc780ba5ed09a85c7d2be1fd08e35 (diff)
parent3558fdc6f56de5d7055af77a7bbb5f9fca876f51 (diff)
Merge branch 'stable-3.5' into stable-3.6
* stable-3.5: Reset pageResultSize when PaginationType NONE back-fill results Add test paginationType NONE to query only if there are more results Fix paginationType NONE to run further queries only if needed Run tests in FakeQueryChangesTest for paginationType NONE Fix detection of invalid SSH key algorithm Demonstrate SshKeyUtil fails to validate invalid SSH keys Move comment of PaginatingSource.read() Fix visibility filter for changes when paginationType NONE Add tests for pagination to back fill the results Allow plugins to use PredicateArgs Release-Notes: skip Change-Id: I8e166780d069267e3f25c454dc947ebe1d32d949
Diffstat (limited to 'java/com/google/gerrit/index/query/PaginatingSource.java')
-rw-r--r--java/com/google/gerrit/index/query/PaginatingSource.java67
1 files changed, 40 insertions, 27 deletions
diff --git a/java/com/google/gerrit/index/query/PaginatingSource.java b/java/com/google/gerrit/index/query/PaginatingSource.java
index 03d749ac14..84572d712a 100644
--- a/java/com/google/gerrit/index/query/PaginatingSource.java
+++ b/java/com/google/gerrit/index/query/PaginatingSource.java
@@ -63,42 +63,55 @@ public class PaginatingSource<T> implements DataSource<T> {
pageResultSize++;
}
- if (last != null
- && source instanceof Paginated
- // TODO: this fix is only for the stable branches and the real refactoring would be to
- // restore the logic
- // for the filtering in AndSource (L58 - 64) as per
- // https://gerrit-review.googlesource.com/c/gerrit/+/345634/9
- && !indexConfig.paginationType().equals(PaginationType.NONE)) {
+ if (last != null && source instanceof Paginated) {
// Restart source and continue if we have not filled the
// full limit the caller wants.
- //
@SuppressWarnings("unchecked")
Paginated<T> p = (Paginated<T>) source;
QueryOptions opts = p.getOptions();
final int limit = opts.limit();
- int pageSize = opts.pageSize();
- int pageSizeMultiplier = opts.pageSizeMultiplier();
- Object searchAfter = resultSet.searchAfter();
- int nextStart = pageResultSize;
- while (pageResultSize == pageSize && r.size() <= limit) { // get 1 more than the limit
- pageSize = getNextPageSize(pageSize, pageSizeMultiplier);
- ResultSet<T> next =
- indexConfig.paginationType().equals(PaginationType.SEARCH_AFTER)
- ? p.restart(searchAfter, pageSize)
- : p.restart(nextStart, pageSize);
- pageResultSize = 0;
- for (T data : buffer(next)) {
- if (match(data)) {
- r.add(data);
+
+ // TODO: this fix is only for the stable branches and the real refactoring would be to
+ // restore the logic
+ // for the filtering in AndSource (L58 - 64) as per
+ // https://gerrit-review.googlesource.com/c/gerrit/+/345634/9
+ if (!indexConfig.paginationType().equals(PaginationType.NONE)) {
+ int pageSize = opts.pageSize();
+ int pageSizeMultiplier = opts.pageSizeMultiplier();
+ Object searchAfter = resultSet.searchAfter();
+ int nextStart = pageResultSize;
+ while (pageResultSize == pageSize && r.size() <= limit) { // get 1 more than the limit
+ pageSize = getNextPageSize(pageSize, pageSizeMultiplier);
+ ResultSet<T> next =
+ indexConfig.paginationType().equals(PaginationType.SEARCH_AFTER)
+ ? p.restart(searchAfter, pageSize)
+ : p.restart(nextStart, pageSize);
+ pageResultSize = 0;
+ for (T data : buffer(next)) {
+ if (match(data)) {
+ r.add(data);
+ }
+ pageResultSize++;
+ if (r.size() > limit) {
+ break;
+ }
}
- pageResultSize++;
- if (r.size() > limit) {
- break;
+ nextStart += pageResultSize;
+ searchAfter = next.searchAfter();
+ }
+ } else {
+ int nextStart = pageResultSize;
+ while (pageResultSize == limit && r.size() < limit) {
+ ResultSet<T> next = p.restart(nextStart);
+ pageResultSize = 0;
+ for (T data : buffer(next)) {
+ if (match(data)) {
+ r.add(data);
+ }
+ pageResultSize++;
}
+ nextStart += pageResultSize;
}
- nextStart += pageResultSize;
- searchAfter = next.searchAfter();
}
}