graphql-anycable icon indicating copy to clipboard operation
graphql-anycable copied to clipboard

optimization Cleaner

Open prog-supdex opened this issue 2 years ago • 2 comments

Here was added a new HASH key objects:list-created-times

After creating subscriptions (and channels later), we will add a subscription's name and the current time to this hash. We will use it in GraphQL::AnyCable::Cleaner to remove the old keys, who has created_time + config.subscription_expiration_seconds

But there is one problem. If we have config.subscription_expiration_seconds, we will set EXPIRE here It means that when Redis destroys this key, this key will remain storing in objects:list-created-times hash

I also considered a separate key, something like this

time:graphql-subscription:some_unique_hash

In other words, every subscription had a Redis key, where has a name time:#{subscription_key_name} and value as the current date But I refused this idea because it creates a lot of records in Redis (one subscription = one time:subscription), but there was a plus - we could set expire for every key

This is not the final PR

prog-supdex avatar Sep 18 '23 15:09 prog-supdex

Let's separate the docs update and the addition of objects:list-created-times into two PRs.

palkan avatar Sep 18 '23 20:09 palkan

Now, It works like that

We have two additional keys, subscription-storage-time and channel-storage-time, which are used to fill up a subscription and channel keys when we do not have subscription_expiration_seconds because if we have the setting subscription_expiration_seconds, it means that subscriptions and channels will be deleted automatically by Redis because in that case, we set TTL for subscription and channel keys

The GraphQL::AnyCable::Cleaner cleans subscriptions and channels using the subscription-storage-time and channel-storage-time keys. It will remove subscription/channel keys with keys from storage if their created_time is earlier than Time.now - config.subscription_expiration_seconds

But, maybe we need to add an ability to set an argument to methods clean_subscriptions and clean_channels, which will be in charge of the time_point, before which the keys should be deleted

Also, if a channel/subscription is deleted, it will remove this key from storage-time

prog-supdex avatar Sep 19 '23 16:09 prog-supdex