Skip to content

Commit 0279e0e

Browse files
authored
Prevent presence background jobs from running when presence is disabled (matrix-org#9530)
Prevent presence background jobs from running when presence is disabled Signed-off-by: Aaron Raimist <[email protected]>
1 parent aee1076 commit 0279e0e

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

changelog.d/9530.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent presence background jobs from running when presence is disabled.

synapse/handlers/presence.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,25 @@ def __init__(self, hs: "HomeServer"):
274274

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

277-
# Start a LoopingCall in 30s that fires every 5s.
278-
# The initial delay is to allow disconnected clients a chance to
279-
# reconnect before we treat them as offline.
280-
def run_timeout_handler():
281-
return run_as_background_process(
282-
"handle_presence_timeouts", self._handle_timeouts
283-
)
284-
285-
self.clock.call_later(30, self.clock.looping_call, run_timeout_handler, 5000)
277+
if self._presence_enabled:
278+
# Start a LoopingCall in 30s that fires every 5s.
279+
# The initial delay is to allow disconnected clients a chance to
280+
# reconnect before we treat them as offline.
281+
def run_timeout_handler():
282+
return run_as_background_process(
283+
"handle_presence_timeouts", self._handle_timeouts
284+
)
286285

287-
def run_persister():
288-
return run_as_background_process(
289-
"persist_presence_changes", self._persist_unpersisted_changes
286+
self.clock.call_later(
287+
30, self.clock.looping_call, run_timeout_handler, 5000
290288
)
291289

292-
self.clock.call_later(60, self.clock.looping_call, run_persister, 60 * 1000)
290+
def run_persister():
291+
return run_as_background_process(
292+
"persist_presence_changes", self._persist_unpersisted_changes
293+
)
294+
295+
self.clock.call_later(60, self.clock.looping_call, run_persister, 60 * 1000)
293296

294297
LaterGauge(
295298
"synapse_handlers_presence_wheel_timer_size",
@@ -299,7 +302,7 @@ def run_persister():
299302
)
300303

301304
# Used to handle sending of presence to newly joined users/servers
302-
if hs.config.use_presence:
305+
if self._presence_enabled:
303306
self.notifier.add_replication_callback(self.notify_new_event)
304307

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

0 commit comments

Comments
 (0)