summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
authorErik Johnston <erikj@matrix.org>2023-09-14 16:20:47 +0100
committerGitHub <noreply@github.com>2023-09-14 16:20:47 +0100
commit329597022ee02516e5cbee11fcd566e05609b724 (patch)
tree386ca9ea5f6d47308a8832f009da92f0e6754917 /synapse/storage/databases
parentSpeed up deleting to-device messages task (#16318) (diff)
downloadsynapse-329597022ee02516e5cbee11fcd566e05609b724.tar.xz
Some minor performance fixes for task schedular (#16313)
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/main/task_scheduler.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/task_scheduler.py b/synapse/storage/databases/main/task_scheduler.py
index 9ab120eea9..5c5372a825 100644
--- a/synapse/storage/databases/main/task_scheduler.py
+++ b/synapse/storage/databases/main/task_scheduler.py
@@ -53,6 +53,7 @@ class TaskSchedulerWorkerStore(SQLBaseStore):
         resource_id: Optional[str] = None,
         statuses: Optional[List[TaskStatus]] = None,
         max_timestamp: Optional[int] = None,
+        limit: Optional[int] = None,
     ) -> List[ScheduledTask]:
         """Get a list of scheduled tasks from the DB.
 
@@ -62,6 +63,7 @@ class TaskSchedulerWorkerStore(SQLBaseStore):
             statuses: Limit the returned tasks to the specific statuses
             max_timestamp: Limit the returned tasks to the ones that have
                 a timestamp inferior to the specified one
+            limit: Only return `limit` number of rows if set.
 
         Returns: a list of `ScheduledTask`, ordered by increasing timestamps
         """
@@ -94,6 +96,10 @@ class TaskSchedulerWorkerStore(SQLBaseStore):
 
             sql = sql + " ORDER BY timestamp"
 
+            if limit is not None:
+                sql += " LIMIT ?"
+                args.append(limit)
+
             txn.execute(sql, args)
             return self.db_pool.cursor_to_dict(txn)