Class: ChronoForge::Dashboard::StatsQuery

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

Overview

Per-state workflow counts, each capped so the panel never pays for an unbounded COUNT. Each count is an index-only COUNT over a ‘LIMIT CAP` subquery on the (state, …) index, so it costs O(CAP) regardless of how many rows match; a saturated count renders as “CAP+”.

Constant Summary collapse

CAP =
5000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base: ChronoForge::Workflow.all, cap: CAP) ⇒ StatsQuery

Returns a new instance of StatsQuery.



10
11
12
13
# File 'app/queries/chrono_forge/dashboard/stats_query.rb', line 10

def initialize(base: ChronoForge::Workflow.all, cap: CAP)
  @base = base
  @cap = cap
end

Instance Attribute Details

#capObject (readonly)

Returns the value of attribute cap.



15
16
17
# File 'app/queries/chrono_forge/dashboard/stats_query.rb', line 15

def cap
  @cap
end

Instance Method Details

#countsObject



17
18
19
20
21
# File 'app/queries/chrono_forge/dashboard/stats_query.rb', line 17

def counts
  ChronoForge::Workflow.states.keys.index_with do |name|
    capped(@base.where(state: ChronoForge::Workflow.states[name]))
  end
end