'Gets called when shutting down. This lets us persist any updates that
we haven\'t yet persisted, e.g. updates that only changes some internal
timers. This allows changes to persist across startup without having to
persist every single change.
If this does not run it simply means that some of the timers will fire
earlier than they should when synapse is restarted. This affect of this
is some spurious presence changes that will self-correct.'

@defer.inlineCallbacks
def _on_shutdown(self):

    logger.info('Performing    _on_shutdown.    Persisting    %d    unpersisted    changes', len(self.user_to_current_state))
    if self.unpersisted_users_changes:
        (yield self.store.update_presence([self.user_to_current_state[user_id] for user_id in self.unpersisted_users_changes]))
    logger.info('Finished    _on_shutdown')
