Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
Last active August 28, 2024 13:54
Show Gist options
  • Save rmosolgo/26a47ce75321b34683b46aa2b630cd53 to your computer and use it in GitHub Desktop.
Save rmosolgo/26a47ce75321b34683b46aa2b630cd53 to your computer and use it in GitHub Desktop.
Remove orphaned subscriptions
# This module will add a method
# to remove unsubscribed subscriptions:
module RemoveUnsubscribedSubscriptionsExtension
def remove_unsubscribed
all_topics, _topics_count = topics(limit: nil, offset: nil)
all_topics.each do |topic|
active_ids = []
# This method will remove any subscriptions where are listed by the topic
# but not actually present in the DB (if this happens, it's a data consistency issue)
each_subscription_id(topic.name) do |id|
active_ids << id
end
# This method checks the transport service (Pusher or Ably)
# and removes any subscriptions that aren't online there
filter_still_subscribed(active_ids)
end
end
end
# Add the method to GraphQL-Pro's subscriptions class:
GraphQL::Pro::Subscriptions.include(RemoveUnsubscribedSubscriptionsExtension)
# Call the method on your schema's subscriptions system:
MySchema.subscriptions.remove_unsubscribed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment