diff options
author | Erik Johnston <erik@matrix.org> | 2016-08-30 15:39:50 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-08-30 15:39:50 +0100 |
commit | 21b977ccfe11832aa1c7b448c6e657cf0df36ad4 (patch) | |
tree | 970b0d8cbab758ee4ec86cb2d7a1636b2d14e876 /synapse/handlers/presence.py | |
parent | Merge pull request #1051 from matrix-org/erikj/fix_push_names (diff) | |
download | synapse-21b977ccfe11832aa1c7b448c6e657cf0df36ad4.tar.xz |
Occaisonally persist unpersisted presence updates
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/presence.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 73752b2f89..a3c7952a4c 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -191,6 +191,13 @@ class PresenceHandler(object): 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 @@ -217,6 +224,27 @@ class PresenceHandler(object): 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 self.unpersisted_users_changes: + 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 the notifier and federation if and only if the changed presence state |