Module: GraphQL::AnyCable::Cleaner
Instance Method Summary collapse
- #clean ⇒ Object
- #clean_channels ⇒ Object
- #clean_fingerprint_subscriptions ⇒ Object
- #clean_subscriptions ⇒ Object
- #clean_topic_fingerprints ⇒ Object
Instance Method Details
#clean ⇒ Object
8 9 10 11 12 13 |
# File 'lib/graphql/anycable/cleaner.rb', line 8 def clean clean_channels clean_subscriptions clean_fingerprint_subscriptions clean_topic_fingerprints end |
#clean_channels ⇒ Object
15 16 17 18 19 20 |
# File 'lib/graphql/anycable/cleaner.rb', line 15 def clean_channels return unless config.subscription_expiration_seconds return unless config.use_redis_object_on_cleanup clean_idle_keys(adapter::CHANNEL_PREFIX) end |
#clean_fingerprint_subscriptions ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/anycable/cleaner.rb', line 29 def clean_fingerprint_subscriptions AnyCable.with_redis do |redis| each_key(redis, adapter::SUBSCRIPTIONS_PREFIX) do |key| each_batch(redis.sscan_each(key, count: redis_scan_count)) do |subscription_ids| stale = missing_key_ids(redis, adapter::SUBSCRIPTION_PREFIX, subscription_ids) redis.srem(key, stale) unless stale.empty? end end end end |
#clean_subscriptions ⇒ Object
22 23 24 25 26 27 |
# File 'lib/graphql/anycable/cleaner.rb', line 22 def clean_subscriptions return unless config.subscription_expiration_seconds return unless config.use_redis_object_on_cleanup clean_idle_keys(adapter::SUBSCRIPTION_PREFIX) end |
#clean_topic_fingerprints ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql/anycable/cleaner.rb', line 40 def clean_topic_fingerprints AnyCable.with_redis do |redis| each_key(redis, adapter::FINGERPRINTS_PREFIX) do |key| redis.zremrangebyscore(key, "-inf", "0") each_batch(redis.zscan_each(key, count: redis_scan_count)) do |members| fingerprints = members.map(&:first) stale = missing_key_ids(redis, adapter::SUBSCRIPTIONS_PREFIX, fingerprints) redis.zrem(key, stale) unless stale.empty? end end end end |