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

Only get cached state from context in persist_event #3584

Merged
merged 3 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changelog.d/3584.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lazily load state on master process when using workers to reduce DB consumption
13 changes: 13 additions & 0 deletions synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def deserialize(store, input):
context._prev_state_id = input["prev_state_id"]
context._event_type = input["event_type"]
context._event_state_key = input["event_state_key"]

context._current_state_ids = None
context._prev_state_ids = None
context._fetching_state_deferred = None

context.state_group = input["state_group"]
Expand Down Expand Up @@ -214,6 +217,16 @@ def get_prev_state_ids(self, store):

defer.returnValue(self._prev_state_ids)

def get_cached_current_state_ids(self):
"""Gets the current state IDs if we have them already cached.

Returns:
dict[(str, str), str]|None: Returns None if state_group
is None, which happens when the associated event is an outlier.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or if we don't have a cache, presumably

"""

return self._current_state_ids

@defer.inlineCallbacks
def _fill_out_state(self, store):
"""Called to populate the _current_state_ids and _prev_state_ids
Expand Down
4 changes: 3 additions & 1 deletion synapse/storage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ def _get_new_state_after_events(self, room_id, events_context, old_latest_event_
if ctx.state_group in state_groups_map:
continue

state_groups_map[ctx.state_group] = yield ctx.get_current_state_ids(self)
current_state_ids = ctx.get_cached_current_state_ids()
if current_state_ids is not None:
state_groups_map[ctx.state_group] = current_state_ids
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do with a comment here


# We need to map the event_ids to their state groups. First, let's
# check if the event is one we're persisting, in which case we can
Expand Down