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

Fix EventContext when using workers #3581

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/3581.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
14 changes: 7 additions & 7 deletions synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class EventContext(object):
"_fetching_state_deferred",
]

def __init__(self):
self.prev_state_events = []
self.rejected = False
self.app_service = None

@staticmethod
def with_state(state_group, current_state_ids, prev_state_ids,
prev_group=None, delta_ids=None):
Expand All @@ -103,11 +108,6 @@ def with_state(state_group, current_state_ids, prev_state_ids,
context.prev_group = prev_group
context.delta_ids = delta_ids

context.prev_state_events = []

context.rejected = False
context.app_service = None

return context

def serialize(self, event):
Expand Down Expand Up @@ -143,7 +143,6 @@ def serialize(self, event):
}

@staticmethod
@defer.inlineCallbacks
def deserialize(store, input):
"""Converts a dict that was produced by `serialize` back into a
EventContext.
Expand All @@ -162,6 +161,7 @@ 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._fetching_state_deferred = None

context.state_group = input["state_group"]
context.prev_group = input["prev_group"]
Expand All @@ -174,7 +174,7 @@ def deserialize(store, input):
if app_service_id:
context.app_service = store.get_app_service_by_id(app_service_id)

defer.returnValue(context)
return context

@defer.inlineCallbacks
def get_current_state_ids(self, store):
Expand Down