PaginatingSource: Stop matching changes after desired limit is reached
Matching changes more than the limit is just extra work that is
discarded at the end when the results are trimmed to match the limit.
This can help improve performance of queries where a small percentage
of changes are filtered in the initial page and the remaining results
are obtained from the next page.
Release-Notes: Improved performance of queries when backend index returns more results than needed
Change-Id: If6cb308eac45151e61bdff9221a2b2b7eda5c47b
diff --git a/java/com/google/gerrit/index/query/PaginatingSource.java b/java/com/google/gerrit/index/query/PaginatingSource.java
index fd3a218..b05c8f4 100644
--- a/java/com/google/gerrit/index/query/PaginatingSource.java
+++ b/java/com/google/gerrit/index/query/PaginatingSource.java
@@ -87,6 +87,9 @@
r.add(data);
}
pageResultSize++;
+ if (r.size() > limit) {
+ break;
+ }
}
nextStart += pageResultSize;
searchAfter = next.searchAfter();