Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Prevent presence background jobs from running when presence is disabl…
Browse files Browse the repository at this point in the history
…ed (#9530)

Prevent presence background jobs from running when presence is disabled

Signed-off-by: Aaron Raimist <aaron@raim.ist>
  • Loading branch information
aaronraimist committed Mar 3, 2021
1 parent aee1076 commit 0279e0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/9530.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent presence background jobs from running when presence is disabled.
31 changes: 17 additions & 14 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,25 @@ def __init__(self, hs: "HomeServer"):

self.external_sync_linearizer = Linearizer(name="external_sync_linearizer")

# Start a LoopingCall in 30s that fires every 5s.
# The initial delay is to allow disconnected clients a chance to
# reconnect before we treat them as offline.
def run_timeout_handler():
return run_as_background_process(
"handle_presence_timeouts", self._handle_timeouts
)

self.clock.call_later(30, self.clock.looping_call, run_timeout_handler, 5000)
if self._presence_enabled:
# Start a LoopingCall in 30s that fires every 5s.
# The initial delay is to allow disconnected clients a chance to
# reconnect before we treat them as offline.
def run_timeout_handler():
return run_as_background_process(
"handle_presence_timeouts", self._handle_timeouts
)

def run_persister():
return run_as_background_process(
"persist_presence_changes", self._persist_unpersisted_changes
self.clock.call_later(
30, self.clock.looping_call, run_timeout_handler, 5000
)

self.clock.call_later(60, self.clock.looping_call, run_persister, 60 * 1000)
def run_persister():
return run_as_background_process(
"persist_presence_changes", self._persist_unpersisted_changes
)

self.clock.call_later(60, self.clock.looping_call, run_persister, 60 * 1000)

LaterGauge(
"synapse_handlers_presence_wheel_timer_size",
Expand All @@ -299,7 +302,7 @@ def run_persister():
)

# Used to handle sending of presence to newly joined users/servers
if hs.config.use_presence:
if self._presence_enabled:
self.notifier.add_replication_callback(self.notify_new_event)

# Presence is best effort and quickly heals itself, so lets just always
Expand Down

0 comments on commit 0279e0e

Please sign in to comment.