mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-09-20 03:14:35 -04:00
Factor out a separate EventContext.for_outlier
(#10883)
Constructing an EventContext for an outlier is actually really simple, and there's no sense in going via an `async` method in the `StateHandler`. This also means that we can resolve a bunch of FIXMEs.
This commit is contained in:
parent
f78b68a96b
commit
26f2bfedbf
5 changed files with 21 additions and 44 deletions
|
@ -263,7 +263,9 @@ class StateHandler:
|
|||
async def compute_event_context(
|
||||
self, event: EventBase, old_state: Optional[Iterable[EventBase]] = None
|
||||
) -> EventContext:
|
||||
"""Build an EventContext structure for the event.
|
||||
"""Build an EventContext structure for a non-outlier event.
|
||||
|
||||
(for an outlier, call EventContext.for_outlier directly)
|
||||
|
||||
This works out what the current state should be for the event, and
|
||||
generates a new state group if necessary.
|
||||
|
@ -278,35 +280,7 @@ class StateHandler:
|
|||
The event context.
|
||||
"""
|
||||
|
||||
if event.internal_metadata.is_outlier():
|
||||
# If this is an outlier, then we know it shouldn't have any current
|
||||
# state. Certainly store.get_current_state won't return any, and
|
||||
# persisting the event won't store the state group.
|
||||
|
||||
# FIXME: why do we populate current_state_ids? I thought the point was
|
||||
# that we weren't supposed to have any state for outliers?
|
||||
if old_state:
|
||||
prev_state_ids = {(s.type, s.state_key): s.event_id for s in old_state}
|
||||
if event.is_state():
|
||||
current_state_ids = dict(prev_state_ids)
|
||||
key = (event.type, event.state_key)
|
||||
current_state_ids[key] = event.event_id
|
||||
else:
|
||||
current_state_ids = prev_state_ids
|
||||
else:
|
||||
current_state_ids = {}
|
||||
prev_state_ids = {}
|
||||
|
||||
# We don't store state for outliers, so we don't generate a state
|
||||
# group for it.
|
||||
context = EventContext.with_state(
|
||||
state_group=None,
|
||||
state_group_before_event=None,
|
||||
current_state_ids=current_state_ids,
|
||||
prev_state_ids=prev_state_ids,
|
||||
)
|
||||
|
||||
return context
|
||||
assert not event.internal_metadata.is_outlier()
|
||||
|
||||
#
|
||||
# first of all, figure out the state before the event
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue