From e945f301d1091e9a09e03debf729d7ecae515f7c Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 16 Feb 2022 11:18:13 +0000 Subject: [PATCH] PERF: Skip running 'auto_leave' during every PresenceChannel method (#15970) These calls were originally introduced to ensure that any stale users were cleaned up regularly. This is quite an expensive process to run on every `GET /presence/get` call, and will also cause errors during readonly mode. Since the original introduction of this logic, we added the `Jobs::PresenceChannelAutoLeave` which runs every minute. That should be enough to clean up any stale users. Note that users which explicitly `leave` a channel are still removed immediately. This auto_leave logic just takes care of clients which have disappeared without leaving. --- lib/presence_channel.rb | 6 ------ spec/components/presence_channel_spec.rb | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/presence_channel.rb b/lib/presence_channel.rb index 757da7c9912..82c9db540b6 100644 --- a/lib/presence_channel.rb +++ b/lib/presence_channel.rb @@ -129,8 +129,6 @@ class PresenceChannel release_mutex(mutex_value) end end - - auto_leave end # Immediately mark a user's client as leaving the channel @@ -151,16 +149,12 @@ class PresenceChannel release_mutex(mutex_value) end end - - auto_leave end # Fetch a {PresenceChannel::State} instance representing the current state of this # # @param [Boolean] count_only set true to skip fetching the list of user ids from redis def state(count_only: config.count_only) - auto_leave - if count_only last_id, count = retry_on_mutex_error do PresenceChannel.redis_eval( diff --git a/spec/components/presence_channel_spec.rb b/spec/components/presence_channel_spec.rb index 1508f790146..09996c567af 100644 --- a/spec/components/presence_channel_spec.rb +++ b/spec/components/presence_channel_spec.rb @@ -74,6 +74,8 @@ describe PresenceChannel do freeze_time Time.zone.now + 1 + PresenceChannel::DEFAULT_TIMEOUT + Jobs::PresenceChannelAutoLeave.new.execute({}) + expect(channel.count).to eq(0) end