mirror of
https://github.com/element-hq/synapse.git
synced 2026-10-29 03:23:22 +00:00
Prefer simple_update_txn
See https://github.com/element-hq/synapse/pull/17512#discussion_r1726808112
This commit is contained in:
1 parent
fc73b6ffc9
commit
980ee9aad6
2 files changed
+14
-11
No files matched your search
@@ -35,6 +35,7 @@ from typing import (
|
||||
Iterable,
|
||||
Iterator,
|
||||
List,
|
||||
Mapping,
|
||||
Optional,
|
||||
Sequence,
|
||||
Tuple,
|
||||
@@ -1966,8 +1967,8 @@ class DatabasePool:
|
||||
def simple_update_txn(
|
||||
txn: LoggingTransaction,
|
||||
table: str,
|
||||
keyvalues: Dict[str, Any],
|
||||
updatevalues: Dict[str, Any],
|
||||
keyvalues: Mapping[str, Any],
|
||||
updatevalues: Mapping[str, Any],
|
||||
) -> int:
|
||||
"""
|
||||
Update rows in the given database table.
|
||||
|
||||
@@ -1708,16 +1708,18 @@ class PersistEventsStore:
|
||||
# instead because there is no `event_id` to use for the `NON NULL`
|
||||
# constraint on `event_stream_ordering`.
|
||||
elif to_delete:
|
||||
args = list(sliding_sync_updates_values) + [room_id]
|
||||
txn.execute(
|
||||
f"""
|
||||
UPDATE sliding_sync_joined_rooms
|
||||
SET
|
||||
{", ".join(f"{key} = ?" for key in sliding_sync_updates_keys)}
|
||||
WHERE room_id = ?
|
||||
""",
|
||||
args,
|
||||
num_rows_updated = self.db_pool.simple_update_txn(
|
||||
txn,
|
||||
table="sliding_sync_joined_rooms",
|
||||
keyvalues={
|
||||
"room_id": room_id,
|
||||
},
|
||||
updatevalues=sliding_sync_table_changes.joined_room_updates,
|
||||
)
|
||||
# TODO: Is this assumption correct?
|
||||
assert (
|
||||
num_rows_updated > 0
|
||||
), "Expected to only run this against existing rows"
|
||||
|
||||
# We now update `local_current_membership`. We do this regardless
|
||||
# of whether we're still in the room or not to handle the case where
|
||||
|
||||
Reference in new issue
Block a user