summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2019-04-02 18:23:32 +0100
committerGitHub <noreply@github.com>2019-04-02 18:23:32 +0100
commit3039d61baf7b4ab914a2d659737337cd09127a51 (patch)
tree672c4e457a5596a408423ff37c1ead65475f73b3 /synapse/storage
parentTransfer related groups on room upgrade (#4990) (diff)
parents/misc/feature/ (diff)
downloadsynapse-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.py30
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.