Skip to content

Commit d49827d

Browse files
committed
Fix-up calls to end_to_end_keys.
1 parent 93b1740 commit d49827d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

synapse/storage/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def execute_batch(self, sql: str, args: Iterable[Iterable[Any]]) -> None:
405405
def execute_values(
406406
self,
407407
sql: str,
408-
values: Iterable[Iterable[Any]],
408+
values: Collection[Iterable[Any]],
409409
template: Optional[str] = None,
410410
fetch: bool = True,
411411
) -> List[Tuple]:
@@ -420,6 +420,10 @@ def execute_values(
420420
"""
421421
assert isinstance(self.database_engine, PostgresEngine)
422422

423+
# If there's no work to do, skip.
424+
if not len(values):
425+
return []
426+
423427
if isinstance(self.database_engine, Psycopg2Engine):
424428
from psycopg2.extras import execute_values
425429

@@ -2431,7 +2435,7 @@ def simple_delete_many_batch_txn(
24312435
values: for each row, a list of values in the same order as `keys`
24322436
"""
24332437

2434-
if isinstance(txn.database_engine, PostgresEngine):
2438+
if isinstance(txn.database_engine, Psycopg2Engine):
24352439
# We use `execute_values` as it can be a lot faster than `execute_batch`,
24362440
# but it's only available on postgres.
24372441
sql = "DELETE FROM %s WHERE (%s) IN (VALUES ?)" % (

synapse/storage/databases/main/end_to_end_keys.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
make_tuple_in_list_sql_clause,
5858
)
5959
from synapse.storage.databases.main.cache import CacheInvalidationWorkerStore
60-
from synapse.storage.engines import PostgresEngine
60+
from synapse.storage.engines import PostgresEngine, Psycopg2Engine
6161
from synapse.storage.util.id_generators import MultiWriterIdGenerator
6262
from synapse.types import JsonDict, JsonMapping
6363
from synapse.util import json_decoder, json_encoder
@@ -1134,7 +1134,7 @@ async def claim_e2e_one_time_keys(
11341134
"""
11351135
results: Dict[str, Dict[str, Dict[str, JsonDict]]] = {}
11361136
missing: List[Tuple[str, str, str, int]] = []
1137-
if isinstance(self.database_engine, PostgresEngine):
1137+
if isinstance(self.database_engine, Psycopg2Engine):
11381138
# If we can use execute_values we can use a single batch query
11391139
# in autocommit mode.
11401140
unfulfilled_claim_counts: Dict[Tuple[str, str, str], int] = {}
@@ -1197,7 +1197,7 @@ async def claim_e2e_fallback_keys(
11971197
Returns:
11981198
A map of user ID -> a map device ID -> a map of key ID -> JSON.
11991199
"""
1200-
if isinstance(self.database_engine, PostgresEngine):
1200+
if isinstance(self.database_engine, Psycopg2Engine):
12011201
return await self.db_pool.runInteraction(
12021202
"_claim_e2e_fallback_keys_bulk",
12031203
self._claim_e2e_fallback_keys_bulk_txn,
@@ -1230,7 +1230,7 @@ def _claim_e2e_fallback_keys_bulk_txn(
12301230
SET used = used OR mark_as_used
12311231
FROM claims
12321232
WHERE (k.user_id, k.device_id, k.algorithm) = (claims.user_id, claims.device_id, claims.algorithm)
1233-
RETURNING k.user_id, k.device_id, k.algorithm, k.key_id, k.key_json;
1233+
RETURNING k.user_id, k.device_id, k.algorithm, k.key_id, k.key_json
12341234
"""
12351235
claimed_keys = cast(
12361236
List[Tuple[str, str, str, str, str]],

0 commit comments

Comments
 (0)