Class: GraphQL::AnyCable::PostgreSQLStore::Store::Cleaner

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

Instance Method Summary collapse

Constructor Details

#initialize(connection_provider:, subscriptions_table:, events_table:, channels_table:) ⇒ Cleaner

Returns a new instance of Cleaner.



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

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

Instance Method Details

#cleanObject



15
16
17
18
19
20
# File 'lib/graphql/anycable/postgresql_store/store/cleaner.rb', line 15

def clean
  clean_subscriptions
  clean_fingerprint_subscriptions
  clean_channels
  clean_topic_fingerprints
end

#clean_channelsObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/graphql/anycable/postgresql_store/store/cleaner.rb', line 22

def clean_channels
  with_connection do |conn|
    conn.exec_params(<<~SQL)
      DELETE FROM #{channels_table} channels
      WHERE NOT EXISTS (
        SELECT 1
        FROM #{subscriptions_table} subscriptions
        WHERE subscriptions.id = channels.subscription_id
      )
    SQL
  end
end

#clean_fingerprint_subscriptionsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/graphql/anycable/postgresql_store/store/cleaner.rb', line 45

def clean_fingerprint_subscriptions
  with_connection do |conn|
    conn.exec_params(<<~SQL)
      DELETE FROM #{events_table} events
      WHERE NOT EXISTS (
        SELECT 1
        FROM #{subscriptions_table} subscriptions
        WHERE subscriptions.id = events.subscription_id
      )
    SQL
  end
end

#clean_subscriptionsObject



35
36
37
38
39
40
41
42
43
# File 'lib/graphql/anycable/postgresql_store/store/cleaner.rb', line 35

def clean_subscriptions
  with_connection do |conn|
    conn.exec_params(<<~SQL)
      DELETE FROM #{subscriptions_table}
      WHERE expires_at IS NOT NULL
        AND expires_at <= CURRENT_TIMESTAMP
    SQL
  end
end

#clean_topic_fingerprintsObject



58
59
60
# File 'lib/graphql/anycable/postgresql_store/store/cleaner.rb', line 58

def clean_topic_fingerprints
  nil
end