diff options
author | Erik Johnston <erikj@jki.re> | 2016-08-30 15:59:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-30 15:59:00 +0100 |
commit | c7f665d7001ee4b2119b93b911b14f241491e7cf (patch) | |
tree | d9f911a81573bbfed08d00e8d3411af211f7fdd9 /synapse | |
parent | Merge pull request #1054 from matrix-org/erikj/presence_noop_online (diff) | |
parent | Check correct variable (diff) | |
download | synapse-c7f665d7001ee4b2119b93b911b14f241491e7cf.tar.xz |
Merge pull request #1055 from matrix-org/erikj/occaisonally_persist
Occaisonally persist unpersisted presence updates
Diffstat (limited to 'synapse')
-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 b5a3bcd660..d22adadc38 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 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 the notifier and federation if and only if the changed presence state |