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

Commit

Permalink
Use simple_select_many_txn in event persistance code. (#16585)
Browse files Browse the repository at this point in the history
Just to standardize on the normal helpers, it might also have
a slight perf improvement on PostgreSQL which will now use
`ANY (?)` instead of `IN (?, ?, ...)`.
  • Loading branch information
clokep committed Nov 2, 2023
1 parent c812f43 commit 0afbef3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/16585.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use standard SQL helpers in persistence code.
16 changes: 11 additions & 5 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,13 +1350,19 @@ def _update_outliers_txn(
PartialStateConflictError: if attempting to persist a partial state event in
a room that has been un-partial stated.
"""
txn.execute(
"SELECT event_id, outlier FROM events WHERE event_id in (%s)"
% (",".join(["?"] * len(events_and_contexts)),),
[event.event_id for event, _ in events_and_contexts],
rows = cast(
List[Tuple[str, bool]],
self.db_pool.simple_select_many_txn(
txn,
"events",
"event_id",
[event.event_id for event, _ in events_and_contexts],
keyvalues={},
retcols=("event_id", "outlier"),
),
)

have_persisted = dict(cast(Iterable[Tuple[str, bool]], txn))
have_persisted = dict(rows)

logger.debug(
"_update_outliers_txn: events=%s have_persisted=%s",
Expand Down

0 comments on commit 0afbef3

Please sign in to comment.