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

Refactor to speed up incremental syncs #2470

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Changes from all commits
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
23 changes: 18 additions & 5 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,22 @@ def _load_filtered_recents(self, room_id, sync_config, now_token,
timeline_limit = sync_config.filter_collection.timeline_limit()
block_all_timeline = sync_config.filter_collection.blocks_all_room_timeline()

# Pull out the current state, as we always want to include those events
# in the timeline if they're there.
current_state_ids = yield self.state.get_current_state_ids(room_id)
current_state_ids = frozenset(current_state_ids.itervalues())

if recents is None or newly_joined_room or timeline_limit < len(recents):
limited = True
else:
limited = False

if recents:
recents = sync_config.filter_collection.filter_room_timeline(recents)

# We check if there are any state events, if there are then we pass
# all current state events to the filter_events function. This is to
# ensure that we always include current state in the timeline
current_state_ids = frozenset()
if any(e.is_state() for e in recents):
current_state_ids = yield self.state.get_current_state_ids(room_id)
current_state_ids = frozenset(current_state_ids.itervalues())

recents = yield filter_events_for_client(
self.store,
sync_config.user.to_string(),
Expand Down Expand Up @@ -341,6 +345,15 @@ def _load_filtered_recents(self, room_id, sync_config, now_token,
loaded_recents = sync_config.filter_collection.filter_room_timeline(
events
)

# We check if there are any state events, if there are then we pass
# all current state events to the filter_events function. This is to
# ensure that we always include current state in the timeline
current_state_ids = frozenset()
if any(e.is_state() for e in loaded_recents):
current_state_ids = yield self.state.get_current_state_ids(room_id)
current_state_ids = frozenset(current_state_ids.itervalues())

loaded_recents = yield filter_events_for_client(
self.store,
sync_config.user.to_string(),
Expand Down