Class: Karafka::Web::Ui::Lib::Paginations::Paginators::Partitions

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/web/ui/lib/paginations/paginators/partitions.rb

Overview

Paginator for selecting proper range of partitions for each page For topics with a lot of partitions we cannot get all the data efficiently, that is why we limit number of partitions per page and reduce the operations that way. This allows us to effectively display more while not having to fetch more partitions then the number of messages per page. In cases like this we distribute partitions evenly part of partitions on each of the pages. This may become unreliable for partitions that are not evenly distributed but this allows us to display data for as many partitions as we want without overloading the system

Class Method Summary collapse

Methods inherited from Base

per_page

Class Method Details

.call(partitions_count, current_page) ⇒ Array<Array<Integer>, Integer, Boolean>

Computers the partitions slice, materialized page and the limitations status for a given page

Parameters:

  • partitions_count (Integer)

    number of partitions for a given topic

  • current_page (Integer)

    current page

Returns:

  • (Array<Array<Integer>, Integer, Boolean>)

    list of partitions that should be active on a given page, materialized page for them and info if we had to limit the partitions number on a given page



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/karafka/web/ui/lib/paginations/paginators/partitions.rb', line 27

def call(partitions_count, current_page)
  # How many "chunks" of partitions we will have
  slices_count = (partitions_count / per_page.to_f).ceil
  # How many partitions in a single slice should we have
  in_slice = (partitions_count / slices_count.to_f).ceil
  # Which "chunked" page do we want to get
  materialized_page = (current_page / slices_count.to_f).ceil
  # Which slice is the one we are operating on
  active_slice_index = (current_page - 1) % slices_count
  # All available slices so we can pick one that is active
  partitions_slices = (0...partitions_count).each_slice(in_slice).to_a
  # Select active partitions only
  active_partitions = partitions_slices[active_slice_index]
  # Are we limiting ourselves because of partition count
  limited = slices_count > 1

  [active_partitions, materialized_page, limited]
end