mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Small speed up joining large remote rooms (#9825)
There are a couple of points in `persist_events` where we are doing a query per event in series, which we can replace.
This commit is contained in:
parent
5a153772c1
commit
601b893352
1
changelog.d/9825.misc
Normal file
1
changelog.d/9825.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Small speed up for joining large remote rooms.
|
@ -1378,16 +1378,20 @@ class PersistEventsStore:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
for event, _ in events_and_contexts:
|
|
||||||
if not event.internal_metadata.is_redacted():
|
|
||||||
# If we're persisting an unredacted event we go and ensure
|
# If we're persisting an unredacted event we go and ensure
|
||||||
# that we mark any redactions that reference this event as
|
# that we mark any redactions that reference this event as
|
||||||
# requiring censoring.
|
# requiring censoring.
|
||||||
self.db_pool.simple_update_txn(
|
sql = "UPDATE redactions SET have_censored = ? WHERE redacts = ?"
|
||||||
txn,
|
txn.execute_batch(
|
||||||
table="redactions",
|
sql,
|
||||||
keyvalues={"redacts": event.event_id},
|
(
|
||||||
updatevalues={"have_censored": False},
|
(
|
||||||
|
False,
|
||||||
|
event.event_id,
|
||||||
|
)
|
||||||
|
for event, _ in events_and_contexts
|
||||||
|
if not event.internal_metadata.is_redacted()
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
state_events_and_contexts = [
|
state_events_and_contexts = [
|
||||||
@ -1881,18 +1885,26 @@ class PersistEventsStore:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
for event, _ in events_and_contexts:
|
room_to_event_ids = {} # type: Dict[str, List[str]]
|
||||||
user_ids = self.db_pool.simple_select_onecol_txn(
|
for e, _ in events_and_contexts:
|
||||||
|
room_to_event_ids.setdefault(e.room_id, []).append(e.event_id)
|
||||||
|
|
||||||
|
for room_id, event_ids in room_to_event_ids.items():
|
||||||
|
rows = self.db_pool.simple_select_many_txn(
|
||||||
txn,
|
txn,
|
||||||
table="event_push_actions_staging",
|
table="event_push_actions_staging",
|
||||||
keyvalues={"event_id": event.event_id},
|
column="event_id",
|
||||||
retcol="user_id",
|
iterable=event_ids,
|
||||||
|
keyvalues={},
|
||||||
|
retcols=("user_id",),
|
||||||
)
|
)
|
||||||
|
|
||||||
for uid in user_ids:
|
user_ids = {row["user_id"] for row in rows}
|
||||||
|
|
||||||
|
for user_id in user_ids:
|
||||||
txn.call_after(
|
txn.call_after(
|
||||||
self.store.get_unread_event_push_actions_by_room_for_user.invalidate_many,
|
self.store.get_unread_event_push_actions_by_room_for_user.invalidate_many,
|
||||||
(event.room_id, uid),
|
(room_id, user_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Now we delete the staging area for *all* events that were being
|
# Now we delete the staging area for *all* events that were being
|
||||||
|
Loading…
Reference in New Issue
Block a user