diff options
author | Erik Johnston <erikj@jki.re> | 2019-04-02 18:23:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-02 18:23:32 +0100 |
commit | 3039d61baf7b4ab914a2d659737337cd09127a51 (patch) | |
tree | 672c4e457a5596a408423ff37c1ead65475f73b3 /synapse/storage | |
parent | Transfer related groups on room upgrade (#4990) (diff) | |
parent | s/misc/feature/ (diff) | |
download | synapse-3039d61baf7b4ab914a2d659737337cd09127a51.tar.xz |
Merge pull request #4991 from matrix-org/erikj/stagger_push_startup
Make starting pushers faster during start up
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/event_push_actions.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/synapse/storage/event_push_actions.py b/synapse/storage/event_push_actions.py index 6840320641..13ce296a9b 100644 --- a/synapse/storage/event_push_actions.py +++ b/synapse/storage/event_push_actions.py @@ -386,6 +386,36 @@ class EventPushActionsWorkerStore(SQLBaseStore): # Now return the first `limit` defer.returnValue(notifs[:limit]) + def get_if_maybe_push_in_range_for_user(self, user_id, min_stream_ordering): + """A fast check to see if there might be something to push for the + user since the given stream ordering. May return false positives. + + Useful to know whether to bother starting a pusher on start up or not. + + Args: + user_id (str) + min_stream_ordering (int) + + Returns: + Deferred[bool]: True if there may be push to process, False if + there definitely isn't. + """ + + def _get_if_maybe_push_in_range_for_user_txn(txn): + sql = """ + SELECT 1 FROM event_push_actions + WHERE user_id = ? AND stream_ordering > ? + LIMIT 1 + """ + + txn.execute(sql, (user_id, min_stream_ordering,)) + return bool(txn.fetchone()) + + return self.runInteraction( + "get_if_maybe_push_in_range_for_user", + _get_if_maybe_push_in_range_for_user_txn, + ) + def add_push_actions_to_staging(self, event_id, user_id_actions): """Add the push actions for the event to the push action staging area. |