瀏覽代碼

Reduce to-device queries for /sync. (#12163)

Erik Johnston 2 年之前
父節點
當前提交
0752ab7a36
共有 2 個文件被更改,包括 4 次插入0 次删除
  1. 1 0
      changelog.d/12163.misc
  2. 3 0
      synapse/storage/databases/main/deviceinbox.py

+ 1 - 0
changelog.d/12163.misc

@@ -0,0 +1 @@
+Reduce number of DB queries made during processing of `/sync`.

+ 3 - 0
synapse/storage/databases/main/deviceinbox.py

@@ -298,6 +298,9 @@ class DeviceInboxWorkerStore(SQLBaseStore):
                 # This user has new messages sent to them. Query messages for them
                 user_ids_to_query.add(user_id)
 
+        if not user_ids_to_query:
+            return {}, to_stream_id
+
         def get_device_messages_txn(txn: LoggingTransaction):
             # Build a query to select messages from any of the given devices that
             # are between the given stream id bounds.