Class: Gitlab::Graphql::Pagination::Keyset::LastItems

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/graphql/pagination/keyset/last_items.rb

Overview

This class handles the last(N) ActiveRecord call even if a special ORDER BY configuration is present. For the last(N) call, ActiveRecord calls reverse_order, however for some cases it raises ActiveRecord::IrreversibleOrderError error.

Class Method Summary collapse

Class Method Details

.take_items(scope, count) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/graphql/pagination/keyset/last_items.rb', line 12

def self.take_items(scope, count)
  if Gitlab::Pagination::Keyset::Order.keyset_aware?(scope)
    order = Gitlab::Pagination::Keyset::Order.extract_keyset_order_object(scope)
    items = scope.reorder(order.reversed_order).first(count)
    items.is_a?(Array) ? items.reverse : items
  else
    scope.last(count)
  end
end