Skip to content

Commit 90387cc

Browse files
committed
Use make_tuple_in_list_sql_clause
Required defining a three-column overload for the method to pass mypy. Additionally the type-ignore was no longer required according to mypy.
1 parent c6534e6 commit 90387cc

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

synapse/storage/database.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,15 +2653,22 @@ def make_in_list_sql_clause(
26532653

26542654

26552655
# These overloads ensure that `columns` and `iterable` values have the same length.
2656-
# Suppress "Single overload definition, multiple required" complaint.
2657-
@overload # type: ignore[misc]
2656+
@overload
26582657
def make_tuple_in_list_sql_clause(
26592658
database_engine: BaseDatabaseEngine,
26602659
columns: Tuple[str, str],
26612660
iterable: Collection[Tuple[Any, Any]],
26622661
) -> Tuple[str, list]: ...
26632662

26642663

2664+
@overload
2665+
def make_tuple_in_list_sql_clause(
2666+
database_engine: BaseDatabaseEngine,
2667+
columns: Tuple[str, str, str],
2668+
iterable: Collection[Tuple[Any, Any, Any]],
2669+
) -> Tuple[str, list]: ...
2670+
2671+
26652672
def make_tuple_in_list_sql_clause(
26662673
database_engine: BaseDatabaseEngine,
26672674
columns: Tuple[str, ...],

synapse/storage/databases/main/end_to_end_keys.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -530,21 +530,20 @@ async def _get_e2e_cross_signing_signatures_for_devices(
530530
def _get_e2e_cross_signing_signatures_for_devices_txn(
531531
txn: LoggingTransaction, device_query: Iterable[Tuple[str, str]]
532532
) -> Mapping[Tuple[str, str], Sequence[Tuple[str, str]]]:
533-
signature_query_clauses = []
534-
signature_query_params = []
535-
536-
for user_id, device_id in device_query:
537-
signature_query_clauses.append(
538-
"target_user_id = ? AND target_device_id = ? AND user_id = ?"
539-
)
540-
signature_query_params.extend([user_id, device_id, user_id])
533+
where_clause_sql, where_clause_params = make_tuple_in_list_sql_clause(
534+
self.database_engine,
535+
columns=("target_user_id", "target_device_id", "user_id"),
536+
iterable=[
537+
(user_id, device_id, user_id) for user_id, device_id in device_query
538+
],
539+
)
541540

542-
signature_sql = """
541+
signature_sql = f"""
543542
SELECT user_id, key_id, target_device_id, signature
544-
FROM e2e_cross_signing_signatures WHERE %s
545-
""" % (" OR ".join("(" + q + ")" for q in signature_query_clauses))
543+
FROM e2e_cross_signing_signatures WHERE {where_clause_sql}
544+
"""
546545

547-
txn.execute(signature_sql, signature_query_params)
546+
txn.execute(signature_sql, where_clause_params)
548547

549548
devices_and_signatures: Dict[Tuple[str, str], List[Tuple[str, str]]] = {}
550549

0 commit comments

Comments
 (0)