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 21 22 23 24 25 |
# 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 redis.scan_each(match: "#{redis_key(adapter::CHANNEL_PREFIX)}*") do |key| idle = redis.object("IDLETIME", key) next if idle&.<= config.subscription_expiration_seconds redis.del(key) end end |
#clean_fingerprint_subscriptions ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/graphql/anycable/cleaner.rb', line 39 def clean_fingerprint_subscriptions redis.scan_each(match: "#{redis_key(adapter::SUBSCRIPTIONS_PREFIX)}*") do |key| redis.smembers(key).each do |subscription_id| next if redis.exists?(redis_key(adapter::SUBSCRIPTION_PREFIX) + subscription_id) redis.srem(key, subscription_id) end end end |
#clean_subscriptions ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/graphql/anycable/cleaner.rb', line 27 def clean_subscriptions return unless config.subscription_expiration_seconds return unless config.use_redis_object_on_cleanup redis.scan_each(match: "#{redis_key(adapter::SUBSCRIPTION_PREFIX)}*") do |key| idle = redis.object("IDLETIME", key) next if idle&.<= config.subscription_expiration_seconds redis.del(key) end end |
#clean_topic_fingerprints ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/graphql/anycable/cleaner.rb', line 49 def clean_topic_fingerprints redis.scan_each(match: "#{redis_key(adapter::FINGERPRINTS_PREFIX)}*") do |key| redis.zremrangebyscore(key, "-inf", "0") redis.zrange(key, 0, -1).each do |fingerprint| next if redis.exists?(redis_key(adapter::SUBSCRIPTIONS_PREFIX) + fingerprint) redis.zrem(key, fingerprint) end end end |