summary refs log tree commit diff
diff options
context:
space:
mode:
authorMathieu Velten <mathieuv@matrix.org>2022-08-02 15:18:57 +0200
committerMathieu Velten <mathieuv@matrix.org>2022-08-02 15:18:57 +0200
commit5de1f166f9615b64c8861e2a5e38a574b34f533c (patch)
treed158a5ba93897b4096b7a6504c68f26b4f787e03
parentApply suggestions from code review (diff)
downloadsynapse-5de1f166f9615b64c8861e2a5e38a574b34f533c.tar.xz
Address comment
-rw-r--r--synapse/storage/databases/main/deviceinbox.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/synapse/storage/databases/main/deviceinbox.py b/synapse/storage/databases/main/deviceinbox.py
index 0bd7ceefeb..79e3862d5f 100644
--- a/synapse/storage/databases/main/deviceinbox.py
+++ b/synapse/storage/databases/main/deviceinbox.py
@@ -218,6 +218,9 @@ class DeviceInboxWorkerStore(SQLBaseStore):
                 * The last-processed stream ID. Subsequent calls of this function with the
                   same device should pass this value as 'from_stream_id'.
         """
+        if limit == 0:
+            return {}, from_stream_id
+
         (
             user_id_device_id_to_messages,
             last_processed_stream_id,
@@ -229,6 +232,10 @@ class DeviceInboxWorkerStore(SQLBaseStore):
             limit=limit,
         )
 
+        if not user_id_device_id_to_messages:
+            # There were no messages!
+            return [], to_stream_id
+
         # Extract the messages, no need to return the user and device ID again
         to_device_messages = user_id_device_id_to_messages.get((user_id, device_id), [])
 
@@ -293,9 +300,6 @@ class DeviceInboxWorkerStore(SQLBaseStore):
                 "without a specific user_id/device_id"
             )
 
-        if limit == 0:
-            return {}, from_stream_id
-
         user_ids_to_query: Set[str] = set()
         device_ids_to_query: Set[str] = set()