Skip to content

Commit

Permalink
fix: consider redis_prefix in GraphQL::AnyCable::Cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Sep 18, 2023
1 parent 8391875 commit 026f543
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/graphql/anycable/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def clean_channels
return unless config.subscription_expiration_seconds
return unless config.use_redis_object_on_cleanup

redis.scan_each(match: "#{adapter::CHANNEL_PREFIX}*") do |key|
redis.scan_each(match: "#{redis_key(adapter::CHANNEL_PREFIX)}*") do |key|
idle = redis.object("IDLETIME", key)
next if idle&.<= config.subscription_expiration_seconds

Expand All @@ -28,7 +28,7 @@ def clean_subscriptions
return unless config.subscription_expiration_seconds
return unless config.use_redis_object_on_cleanup

redis.scan_each(match: "#{adapter::SUBSCRIPTION_PREFIX}*") do |key|
redis.scan_each(match: "#{redis_key(adapter::SUBSCRIPTION_PREFIX)}*") do |key|
idle = redis.object("IDLETIME", key)
next if idle&.<= config.subscription_expiration_seconds

Expand All @@ -37,20 +37,20 @@ def clean_subscriptions
end

def clean_fingerprint_subscriptions
redis.scan_each(match: "#{adapter::SUBSCRIPTIONS_PREFIX}*") do |key|
redis.scan_each(match: "#{redis_key(adapter::SUBSCRIPTIONS_PREFIX)}*") do |key|
redis.smembers(key).each do |subscription_id|
next if redis.exists?(adapter::SUBSCRIPTION_PREFIX + subscription_id)
next if redis.exists?(redis_key(adapter::SUBSCRIPTION_PREFIX) + subscription_id)

redis.srem(key, subscription_id)
end
end
end

def clean_topic_fingerprints
redis.scan_each(match: "#{adapter::FINGERPRINTS_PREFIX}*") do |key|
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?(adapter::SUBSCRIPTIONS_PREFIX + fingerprint)
next if redis.exists?(redis_key(adapter::SUBSCRIPTIONS_PREFIX) + fingerprint)

redis.zrem(key, fingerprint)
end
Expand All @@ -70,6 +70,10 @@ def redis
def config
GraphQL::AnyCable.config
end

def redis_key(prefix)
"#{config.redis_prefix}-#{prefix}"
end
end
end
end

0 comments on commit 026f543

Please sign in to comment.