Merge pull request #3584 from matrix-org/erikj/use_cached
Only get cached state from context in persist_event
This commit is contained in:
commit
f559119de0
|
@ -0,0 +1 @@
|
||||||
|
Lazily load state on master process when using workers to reduce DB consumption
|
|
@ -163,6 +163,9 @@ class EventContext(object):
|
||||||
context._prev_state_id = input["prev_state_id"]
|
context._prev_state_id = input["prev_state_id"]
|
||||||
context._event_type = input["event_type"]
|
context._event_type = input["event_type"]
|
||||||
context._event_state_key = input["event_state_key"]
|
context._event_state_key = input["event_state_key"]
|
||||||
|
|
||||||
|
context._current_state_ids = None
|
||||||
|
context._prev_state_ids = None
|
||||||
context._fetching_state_deferred = None
|
context._fetching_state_deferred = None
|
||||||
|
|
||||||
context.state_group = input["state_group"]
|
context.state_group = input["state_group"]
|
||||||
|
@ -214,6 +217,17 @@ class EventContext(object):
|
||||||
|
|
||||||
defer.returnValue(self._prev_state_ids)
|
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 we haven't cached the
|
||||||
|
state or if state_group is None, which happens when the associated
|
||||||
|
event is an outlier.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._current_state_ids
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _fill_out_state(self, store):
|
def _fill_out_state(self, store):
|
||||||
"""Called to populate the _current_state_ids and _prev_state_ids
|
"""Called to populate the _current_state_ids and _prev_state_ids
|
||||||
|
|
|
@ -549,7 +549,12 @@ class EventsStore(EventsWorkerStore):
|
||||||
if ctx.state_group in state_groups_map:
|
if ctx.state_group in state_groups_map:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
state_groups_map[ctx.state_group] = yield ctx.get_current_state_ids(self)
|
# We're only interested in pulling out state that has already
|
||||||
|
# been cached in the context. We'll pull stuff out of the DB later
|
||||||
|
# if necessary.
|
||||||
|
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
|
||||||
|
|
||||||
# We need to map the event_ids to their state groups. First, let's
|
# 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
|
# check if the event is one we're persisting, in which case we can
|
||||||
|
|
Loading…
Reference in New Issue