From c992eff8e5f0822f629826e2093425880c4fe16c Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Fri, 2 Sep 2022 14:28:17 -0700 Subject: Avoid fetching more results than needed in paginated index queries The 'limit' when paginating the source already has 'start' added to it when query options are converted for index backend. We already have tests ensuring it. Adding it again to 'limit' will fetch us more results than we need. These extra results will eventually be trimmed, but we end-up doing more work than needed. On a test site with ~25k open changes, query-limit of 50 and ES as index backend a query like [1], when run with a user (who can't see most changes) now does 3 index searches and finishes in ~200ms with this change as opposed to 4 and ~250ms without it. Note that, this stat also depends on the fact the visible and non-visible changes are intertwined together. [1] gerrit query 'status:open' --start 40 Release-Notes: skip Change-Id: I99bc17d059b06ec0a904cb0c4036ab2ec2f45d23 --- java/com/google/gerrit/index/query/AndSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/com/google/gerrit/index/query/AndSource.java b/java/com/google/gerrit/index/query/AndSource.java index c99e60ae5a..58b49cf76b 100644 --- a/java/com/google/gerrit/index/query/AndSource.java +++ b/java/com/google/gerrit/index/query/AndSource.java @@ -119,7 +119,7 @@ public class AndSource extends AndPredicate final int limit = p.getOptions().limit(); Object searchAfter = resultSet.searchAfter(); int pageSize = limit; - while (skipped && r.size() < limit + start) { + while (skipped && r.size() < limit) { skipped = false; pageSize = getNextPageSize(pageSize); ResultSet next = -- cgit v1.2.3