Class: ChronoForge::Dashboard::WorkflowsQuery

Inherits:
Object
  • Object
show all
Defined in:
app/queries/chrono_forge/dashboard/workflows_query.rb

Overview

Keyset (cursor) pagination over workflows. Orders by primary key descending (newest first) and pages with id < cursor / id > cursor rather than OFFSET, and never issues a COUNT(*). Both degrade at scale; keyset stays constant-cost at any depth and over any number of rows. Accepts a base scope so it also drives bounded child lists (e.g. a branch's children).

Constant Summary collapse

DEFAULT_PER =
50
MAX_PER =
200

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base: ChronoForge::Workflow.all, state: nil, job_class: nil, key: nil, created_from: nil, created_to: nil, before: nil, after: nil, per: DEFAULT_PER, exclude_branched: false) ⇒ WorkflowsQuery

Returns a new instance of WorkflowsQuery.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 12

def initialize(base: ChronoForge::Workflow.all, state: nil, job_class: nil, key: nil,
  created_from: nil, created_to: nil, before: nil, after: nil, per: DEFAULT_PER,
  exclude_branched: false)
  @base = base
  @state = state.presence
  @job_class = job_class.presence
  @key = key.presence
  @created_from = created_from.presence
  @created_to = created_to.presence
  @before = before.presence&.to_i
  @after = after.presence&.to_i
  @per = per.to_i.clamp(1, MAX_PER)
  # Off by default: the branch-children view drives this same query with a
  # base scoped to a branch's spawned_workflows (all of which ARE branch
  # children), so excluding them there would empty the list. Only the main
  # index opts in, to keep a large fan-out's children out of the top level.
  @exclude_branched = exclude_branched
end

Instance Attribute Details

#perObject (readonly)

Returns the value of attribute per.



36
37
38
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 36

def per
  @per
end

Instance Method Details

#has_next?Boolean

older rows remain

Returns:

  • (Boolean)


38
39
40
41
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 38

def has_next? # older rows remain
  load
  @has_next
end

#has_prev?Boolean

newer rows remain

Returns:

  • (Boolean)


43
44
45
46
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 43

def has_prev? # newer rows remain
  load
  @has_prev
end

#next_cursorObject



48
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 48

def next_cursor = records.last&.id

#prev_cursorObject



49
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 49

def prev_cursor = records.first&.id

#recordsObject



31
32
33
34
# File 'app/queries/chrono_forge/dashboard/workflows_query.rb', line 31

def records
  load
  @records
end