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

Update the stream_cache less often. #16586

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16586.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid updating the stream cache unnecessarily.
22 changes: 13 additions & 9 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,24 +1315,28 @@ def _update_room_depths_txn(
room_id: The room ID
events_and_contexts: events we are persisting
"""
stream_ordering = 0
depth_update = 0
for event, context in events_and_contexts:
# Then update the `stream_ordering` position to mark the latest
# event as the front of the room. This should not be done for
# backfilled events because backfilled events have negative
# stream_ordering and happened in the past so we know that we don't
# need to update the stream_ordering tip/front for the room.
# Don't update the stream ordering for backfilled events because
# backfilled events have negative stream_ordering and happened in the
# past, so we know that we don't need to update the stream_ordering
# tip/front for the room.
assert event.internal_metadata.stream_ordering is not None
if event.internal_metadata.stream_ordering >= 0:
txn.call_after(
self.store._events_stream_cache.entity_has_changed,
event.room_id,
event.internal_metadata.stream_ordering,
stream_ordering = max(
stream_ordering, event.internal_metadata.stream_ordering
)

if not event.internal_metadata.is_outlier() and not context.rejected:
depth_update = max(event.depth, depth_update)

# Then update the `stream_ordering` position to mark the latest event as
# the front of the room.
txn.call_after(
self.store._events_stream_cache.entity_has_changed, room_id, stream_ordering
)
clokep marked this conversation as resolved.
Show resolved Hide resolved

self._update_min_depth_for_room_txn(txn, room_id, depth_update)

def _update_outliers_txn(
Expand Down
Loading