From cf5f79f570c077f428f621c656f75e6f240d062f Mon Sep 17 00:00:00 2001 From: David Robertson Date: Sat, 28 Oct 2023 00:41:51 +0100 Subject: [PATCH] Don't bother using the bulk query on SQLite We could probably use executemany? But I don't care. --- synapse/storage/databases/main/end_to_end_keys.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/synapse/storage/databases/main/end_to_end_keys.py b/synapse/storage/databases/main/end_to_end_keys.py index 4a04400c4d20..39c1d2078d01 100644 --- a/synapse/storage/databases/main/end_to_end_keys.py +++ b/synapse/storage/databases/main/end_to_end_keys.py @@ -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, ) @@ -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]],