Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/graphql/pagination/keyset/connection.rb')
-rw-r--r--lib/gitlab/graphql/pagination/keyset/connection.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/gitlab/graphql/pagination/keyset/connection.rb b/lib/gitlab/graphql/pagination/keyset/connection.rb
index b074c273996..987a5e7b74b 100644
--- a/lib/gitlab/graphql/pagination/keyset/connection.rb
+++ b/lib/gitlab/graphql/pagination/keyset/connection.rb
@@ -59,11 +59,15 @@ module Gitlab
if before
true
elsif first
- case sliced_nodes
- when Array
- sliced_nodes.size > limit_value
+ if Feature.enabled?(:graphql_keyset_pagination_without_next_page_query)
+ limited_nodes.size > limit_value
else
- sliced_nodes.limit(1).offset(limit_value).exists? # rubocop: disable CodeReuse/ActiveRecord
+ case sliced_nodes
+ when Array
+ sliced_nodes.size > limit_value
+ else
+ sliced_nodes.limit(1).offset(limit_value).exists? # rubocop: disable CodeReuse/ActiveRecord
+ end
end
else
false
@@ -89,7 +93,7 @@ module Gitlab
# So we're ok loading them into memory here as that's bound to happen
# anyway. Having them ready means we can modify the result while
# rendering the fields.
- @nodes ||= limited_nodes.to_a
+ @nodes ||= limited_nodes.to_a.take(limit_value) # rubocop: disable CodeReuse/ActiveRecord
end
def items
@@ -116,15 +120,21 @@ module Gitlab
end
if last
- paginated_nodes = LastItems.take_items(sliced_nodes, limit_value + 1)
+ paginated_nodes = sliced_nodes.last(limit_value + 1)
# there is an extra node, so there is a previous page
@has_previous_page = paginated_nodes.count > limit_value
@has_previous_page ? paginated_nodes.last(limit_value) : paginated_nodes
elsif loaded?(sliced_nodes)
- sliced_nodes.take(limit_value) # rubocop: disable CodeReuse/ActiveRecord
+ if Feature.enabled?(:graphql_keyset_pagination_without_next_page_query)
+ sliced_nodes.take(limit_value + 1) # rubocop: disable CodeReuse/ActiveRecord
+ else
+ sliced_nodes.take(limit_value) # rubocop: disable CodeReuse/ActiveRecord
+ end
+ elsif Feature.enabled?(:graphql_keyset_pagination_without_next_page_query)
+ sliced_nodes.limit(limit_value + 1).to_a
else
- sliced_nodes.limit(limit_value) # rubocop: disable CodeReuse/ActiveRecord
+ sliced_nodes.limit(limit_value)
end
end
end
@@ -141,7 +151,7 @@ module Gitlab
def limit_value
# note: only first _or_ last can be specified, not both
- @limit_value ||= [first, last, max_page_size].compact.min
+ @limit_value ||= [first, last, max_page_size, GitlabSchema.default_max_page_size].compact.min
end
def loaded?(items)