Class: Gitlab::Pagination::GitalyKeysetPager

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/pagination/gitaly_keyset_pager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_context, project) ⇒ GitalyKeysetPager

Returns a new instance of GitalyKeysetPager.



10
11
12
13
# File 'lib/gitlab/pagination/gitaly_keyset_pager.rb', line 10

def initialize(request_context, project)
  @request_context = request_context
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



6
7
8
# File 'lib/gitlab/pagination/gitaly_keyset_pager.rb', line 6

def project
  @project
end

#request_contextObject (readonly)

Returns the value of attribute request_context.



6
7
8
# File 'lib/gitlab/pagination/gitaly_keyset_pager.rb', line 6

def request_context
  @request_context
end

Instance Method Details

#paginate(finder) ⇒ Object

It is expected that the given finder will respond to ‘execute` method with `gitaly_pagination:` option and supports pagination via gitaly.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/pagination/gitaly_keyset_pager.rb', line 17

def paginate(finder)
  return finder.execute(gitaly_pagination: false) if no_pagination?(finder)

  return paginate_via_gitaly(finder) if keyset_pagination_enabled?(finder)
  return paginate_first_page_via_gitaly(finder) if paginate_first_page?(finder)

  records = ::Kaminari.paginate_array(finder.execute)
  Gitlab::Pagination::OffsetPagination
    .new(request_context)
    .paginate(records)
end