Use simple_select_many_txn in event persistance code. (#16585)

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 (?, ?, ...)`.
This commit is contained in:
Patrick Cloke 2023-11-02 09:41:00 -04:00 committed by GitHub
parent c812f43bd7
commit 0afbef30cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

1
changelog.d/16585.misc Normal file
View File

@ -0,0 +1 @@
Use standard SQL helpers in persistence code.

View File

@ -1350,13 +1350,19 @@ class PersistEventsStore:
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",