diff options
author | Erik Johnston <erik@matrix.org> | 2019-10-02 19:07:07 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-10-10 13:15:49 +0100 |
commit | b161786c1455f219d58549b514f2551f25eae33a (patch) | |
tree | 4d4ec7936df2a3295c6d57c8cbb0001b34cf9aa6 /synapse/storage/devices.py | |
parent | Add helper funcs to use postgres ANY (diff) | |
download | synapse-b161786c1455f219d58549b514f2551f25eae33a.tar.xz |
Replace IN usage with helper funcs
Diffstat (limited to 'synapse/storage/devices.py')
-rw-r--r-- | synapse/storage/devices.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py index 111bfb3d64..ac5239e50a 100644 --- a/synapse/storage/devices.py +++ b/synapse/storage/devices.py @@ -28,7 +28,12 @@ from synapse.logging.opentracing import ( whitelisted_homeserver, ) from synapse.metrics.background_process_metrics import run_as_background_process -from synapse.storage._base import Cache, SQLBaseStore, db_to_json +from synapse.storage._base import ( + Cache, + SQLBaseStore, + db_to_json, + make_in_list_sql_clause, +) from synapse.storage.background_updates import BackgroundUpdateStore from synapse.util import batch_iter from synapse.util.caches.descriptors import cached, cachedInlineCallbacks, cachedList @@ -448,11 +453,14 @@ class DeviceWorkerStore(SQLBaseStore): sql = """ SELECT DISTINCT user_id FROM device_lists_stream WHERE stream_id > ? - AND user_id IN (%s) + AND """ for chunk in batch_iter(to_check, 100): - txn.execute(sql % (",".join("?" for _ in chunk),), (from_key,) + chunk) + clause, args = make_in_list_sql_clause( + txn.database_engine, "user_id", chunk + ) + txn.execute(sql + clause, (from_key,) + tuple(args)) changes.update(user_id for user_id, in txn) return changes |