Class: GraphQL::AnyCable::PostgreSQLStore::Store::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/anycable/postgresql_store/store/stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection_provider:, subscriptions_table:, events_table:, channels_table:, scan_count:, include_subscriptions:) ⇒ Stats

Returns a new instance of Stats.



8
9
10
11
12
13
14
15
# File 'lib/graphql/anycable/postgresql_store/store/stats.rb', line 8

def initialize(connection_provider:, subscriptions_table:, events_table:, channels_table:, scan_count:, include_subscriptions:)
  @connection_provider = connection_provider
  @subscriptions_table = subscriptions_table
  @events_table = events_table
  @channels_table = channels_table
  @scan_count = scan_count
  @include_subscriptions = include_subscriptions
end

Instance Method Details

#collectObject

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/anycable/postgresql_store/store/stats.rb', line 17

def collect
  # PostgreSQL uses aggregate queries rather than key scans; scan_count
  # is accepted to match graphql-anycable's store stats interface.
  raise ArgumentError, "scan_count must be positive" if scan_count.to_i <= 0

  with_connection do |conn|
    result = {total: total_stats(conn)}
    result[:subscriptions] = subscription_stats(conn) if include_subscriptions
    result
  end
end