Skip to content

Commit

Permalink
Drop handling legacy pre-1.0 subscriptions data
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Mar 11, 2022
1 parent 0ed613d commit 736501c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 60 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Removed

- Handling of pre-1.0 subscriptions data.

If you're still using version 0.5 or below, please upgrade to 1.0 or 1.1 first with `handle_legacy_subscriptions` setting enabled.
See [release notes for version 1.0.0](https://github.com/anycable/graphql-anycable/releases/tag/v1.0.0) for details.

## 1.1.3 - 2022-03-11

### Changed
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ GraphQL-AnyCable uses [anyway_config] to configure itself. There are several pos
```.env
GRAPHQL_ANYCABLE_SUBSCRIPTION_EXPIRATION_SECONDS=604800
GRAPHQL_ANYCABLE_USE_REDIS_OBJECT_ON_CLEANUP=true
GRAPHQL_ANYCABLE_HANDLE_LEGACY_SUBSCRIPTIONS=false
GRAPHQL_ANYCABLE_USE_CLIENT_PROVIDED_UNIQ_ID=false
```
Expand All @@ -151,7 +150,6 @@ GraphQL-AnyCable uses [anyway_config] to configure itself. There are several pos
production:
subscription_expiration_seconds: 300 # 5 minutes
use_redis_object_on_cleanup: false # For restricted redis installations
handle_legacy_subscriptions: false # For seamless upgrade from pre-1.0 versions
use_client_provided_uniq_id: false # To avoid problems with non-uniqueness of Apollo channel identifiers
```
Expand Down Expand Up @@ -183,13 +181,6 @@ As in AnyCable there is no place to store subscription data in-memory, it should
=> 52ee8d65-275e-4d22-94af-313129116388
```
> For backward compatibility with pre-1.0 versions of this gem older `graphql-event:#{event.topic}` set containing subscription identifiers is also supported.
>
> ```
> SMEMBERS graphql-event:1:myStats:
> => 52ee8d65-275e-4d22-94af-313129116388
> ```
3. Subscription data: `graphql-subscription:#{subscription_id}` hash contains everything required to evaluate subscription on trigger and create data for client.
```
Expand Down
16 changes: 0 additions & 16 deletions lib/graphql/anycable/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Cleaner
def clean
clean_channels
clean_subscriptions
clean_events
clean_fingerprint_subscriptions
clean_topic_fingerprints
end
Expand Down Expand Up @@ -37,21 +36,6 @@ def clean_subscriptions
end
end

def clean_events
return unless config.handle_legacy_subscriptions

redis.scan_each(match: "#{adapter::SUBSCRIPTION_EVENTS_PREFIX}*") do |key|
subscription_id = key.sub(/\A#{adapter::SUBSCRIPTION_EVENTS_PREFIX}/, "")
next if redis.exists?(adapter::SUBSCRIPTION_PREFIX + subscription_id)

redis.smembers(key).each do |event_topic|
redis.srem(adapter::EVENT_PREFIX + event_topic, subscription_id)
end

redis.del(key)
end
end

def clean_fingerprint_subscriptions
redis.scan_each(match: "#{adapter::SUBSCRIPTIONS_PREFIX}*") do |key|
redis.smembers(key).each do |subscription_id|
Expand Down
1 change: 0 additions & 1 deletion lib/graphql/anycable/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Config < Anyway::Config

attr_config subscription_expiration_seconds: nil
attr_config use_redis_object_on_cleanup: true
attr_config handle_legacy_subscriptions: false
attr_config use_client_provided_uniq_id: true

on_load do
Expand Down
5 changes: 0 additions & 5 deletions lib/graphql/anycable/tasks/clean_expired_subscriptions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ namespace :graphql do
GraphQL::AnyCable::Cleaner.clean_subscriptions
end

# Clean up legacy subscription_ids from events for expired subscriptions
task :events do
GraphQL::AnyCable::Cleaner.clean_events
end

# Clean up subscription_ids from event fingerprints for expired subscriptions
task :fingerprint_subscriptions do
GraphQL::AnyCable::Cleaner.clean_fingerprint_subscriptions
Expand Down
29 changes: 0 additions & 29 deletions lib/graphql/subscriptions/anycable_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class AnyCableSubscriptions < GraphQL::Subscriptions
FINGERPRINTS_PREFIX = "graphql-fingerprints:" # ZSET: To get fingerprints by topic
SUBSCRIPTIONS_PREFIX = "graphql-subscriptions:" # SET: To get subscriptions by fingerprint
CHANNEL_PREFIX = "graphql-channel:" # SET: Auxiliary structure for whole channel's subscriptions cleanup
# For backward compatibility:
EVENT_PREFIX = "graphql-event:"
SUBSCRIPTION_EVENTS_PREFIX = "graphql-subscription-events:"

# @param serializer [<#dump(obj), #load(string)] Used for serializing messages before handing them to `.broadcast(msg)`
def initialize(serializer: Serialize, **rest)
Expand All @@ -73,8 +70,6 @@ def initialize(serializer: Serialize, **rest)
# An event was triggered.
# Re-evaluate all subscribed queries and push the data over ActionCable.
def execute_all(event, object)
execute_legacy(event, object) if config.handle_legacy_subscriptions

fingerprints = redis.zrange(FINGERPRINTS_PREFIX + event.topic, 0, -1)
return if fingerprints.empty?

Expand Down Expand Up @@ -109,17 +104,6 @@ def execute_grouped(fingerprint, subscription_ids, event, object)
deliver(SUBSCRIPTIONS_PREFIX + fingerprint, result)
end

# For migration from pre-1.0 graphql-anycable gem
def execute_legacy(event, object)
redis.smembers(EVENT_PREFIX + event.topic).each do |subscription_id|
next unless redis.exists?(SUBSCRIPTION_PREFIX + subscription_id)
result = execute_update(subscription_id, event, object)
next unless result

deliver(SUBSCRIPTION_PREFIX + subscription_id, result)
end
end

# Disable this method as there is no fingerprint (it can be retrieved from subscription though)
def execute(subscription_id, event, object)
raise NotImplementedError, "Use execute_all method instead of execute to get actual event fingerprint"
Expand Down Expand Up @@ -206,19 +190,6 @@ def delete_subscription(subscription_id)
pipeline.zremrangebyscore(key, '-inf', '0') if score.value.zero?
end
end
delete_legacy_subscription(subscription_id)
end

def delete_legacy_subscription(subscription_id)
return unless config.handle_legacy_subscriptions

events = redis.smembers(SUBSCRIPTION_EVENTS_PREFIX + subscription_id)
redis.pipelined do
events.each do |event_topic|
redis.srem(EVENT_PREFIX + event_topic, subscription_id)
end
redis.del(SUBSCRIPTION_EVENTS_PREFIX + subscription_id)
end
end

# The channel was closed, forget about it and its subscriptions
Expand Down

0 comments on commit 736501c

Please sign in to comment.