Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Don't bother using the bulk query on SQLite
Browse files Browse the repository at this point in the history
We could probably use executemany? But I don't care.
  • Loading branch information
David Robertson committed Oct 28, 2023
1 parent 3e6c78a commit cf5f79f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions synapse/storage/databases/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,19 +1128,18 @@ async def claim_e2e_one_time_keys(
may be less than the input counts. In this case, the returned counts
are the number of claims that were not fulfilled.
"""

results: Dict[str, Dict[str, Dict[str, JsonDict]]] = {}
missing: List[Tuple[str, str, str, int]] = []
if self.database_engine.supports_returning:
# If we support RETURNING clause we can use a single query that
# allows us to use autocommit mode.
if isinstance(self.database_engine, PostgresEngine):
# If we can use execute_values we can use a single batch query
# in autocommit mode.
unfulfilled_claim_counts: Dict[Tuple[str, str, str], int] = {}
for user_id, device_id, algorithm, count in query_list:
unfulfilled_claim_counts[user_id, device_id, algorithm] = count

bulk_claims = await self.db_pool.runInteraction(
"claim_e2e_one_time_keys",
self._claim_e2e_one_time_keys_returning,
self._claim_e2e_one_time_keys_bulk,
query_list,
db_autocommit=True,
)
Expand Down Expand Up @@ -1283,7 +1282,7 @@ def _claim_e2e_one_time_key_simple(
return [(f"{algorithm}:{key_id}", key_json) for key_id, key_json in otk_rows]

@trace
def _claim_e2e_one_time_keys_returning(
def _claim_e2e_one_time_keys_bulk(
self,
txn: LoggingTransaction,
query_list: Iterable[Tuple[str, str, str, int]],
Expand Down

0 comments on commit cf5f79f

Please sign in to comment.