Class: Gitlab::UpdatedNotesPaginator

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

Overview

UpdatedNotesPaginator implements a rudimentary form of keyset pagination on top of a notes relation that has been initialized with a `last_fetched_at` value. This class will attempt to limit the number of notes returned, and specify a new value for `last_fetched_at` that will pick up where the last page of notes left off.

Constant Summary collapse

LIMIT =
50
MICROSECOND =
1_000_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, last_fetched_at:) ⇒ UpdatedNotesPaginator

Returns a new instance of UpdatedNotesPaginator.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/updated_notes_paginator.rb', line 15

def initialize(relation, last_fetched_at:)
  @last_fetched_at = last_fetched_at
  @now = Time.current

  notes, more = fetch_page(relation)
  if more
    init_middle_page(notes)
  else
    init_final_page(notes)
  end
end

Instance Attribute Details

#next_fetched_atObject (readonly)

Returns the value of attribute next_fetched_at.


13
14
15
# File 'lib/gitlab/updated_notes_paginator.rb', line 13

def next_fetched_at
  @next_fetched_at
end

#notesObject (readonly)

Returns the value of attribute notes.


13
14
15
# File 'lib/gitlab/updated_notes_paginator.rb', line 13

def notes
  @notes
end

Instance Method Details

#metadataObject


27
28
29
# File 'lib/gitlab/updated_notes_paginator.rb', line 27

def 
  { last_fetched_at: next_fetched_at_microseconds, more: more }
end