mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 20:40:10 +08:00
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.
This commit is contained in:
parent
a170c8e708
commit
e945f301d1
@ -129,8 +129,6 @@ class PresenceChannel
|
|||||||
release_mutex(mutex_value)
|
release_mutex(mutex_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
auto_leave
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Immediately mark a user's client as leaving the channel
|
# Immediately mark a user's client as leaving the channel
|
||||||
@ -151,16 +149,12 @@ class PresenceChannel
|
|||||||
release_mutex(mutex_value)
|
release_mutex(mutex_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
auto_leave
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fetch a {PresenceChannel::State} instance representing the current state of this
|
# 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
|
# @param [Boolean] count_only set true to skip fetching the list of user ids from redis
|
||||||
def state(count_only: config.count_only)
|
def state(count_only: config.count_only)
|
||||||
auto_leave
|
|
||||||
|
|
||||||
if count_only
|
if count_only
|
||||||
last_id, count = retry_on_mutex_error do
|
last_id, count = retry_on_mutex_error do
|
||||||
PresenceChannel.redis_eval(
|
PresenceChannel.redis_eval(
|
||||||
|
@ -74,6 +74,8 @@ describe PresenceChannel do
|
|||||||
|
|
||||||
freeze_time Time.zone.now + 1 + PresenceChannel::DEFAULT_TIMEOUT
|
freeze_time Time.zone.now + 1 + PresenceChannel::DEFAULT_TIMEOUT
|
||||||
|
|
||||||
|
Jobs::PresenceChannelAutoLeave.new.execute({})
|
||||||
|
|
||||||
expect(channel.count).to eq(0)
|
expect(channel.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user