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

Commit

Permalink
Merge pull request #1055 from matrix-org/erikj/occaisonally_persist
Browse files Browse the repository at this point in the history
Occaisonally persist unpersisted presence updates
  • Loading branch information
erikjohnston authored Aug 30, 2016
2 parents d3f108b + 097330b commit c7f665d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ def __init__(self, hs):
5000,
)

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

metrics.register_callback("wheel_timer_size", lambda: len(self.wheel_timer))

@defer.inlineCallbacks
Expand All @@ -216,6 +223,27 @@ def _on_shutdown(self):
])
logger.info("Finished _on_shutdown")

@defer.inlineCallbacks
def _persist_unpersisted_changes(self):
"""We periodically persist the unpersisted changes, as otherwise they
may stack up and slow down shutdown times.
"""
logger.info(
"Performing _persist_unpersisted_changes. Persiting %d unpersisted changes",
len(self.user_to_current_state)
)

unpersisted = self.unpersisted_users_changes
self.unpersisted_users_changes = set()

if unpersisted:
yield self.store.update_presence([
self.user_to_current_state[user_id]
for user_id in unpersisted
])

logger.info("Finished _persist_unpersisted_changes")

@defer.inlineCallbacks
def _update_states(self, new_states):
"""Updates presence of users. Sets the appropriate timeouts. Pokes
Expand Down

0 comments on commit c7f665d

Please sign in to comment.