mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-22 01:14:59 -05:00
Short circuit if all new events have same state group
This commit is contained in:
parent
281553afe6
commit
d82c42837f
@ -428,6 +428,7 @@ class EventsStore(SQLBaseStore):
|
|||||||
# Now we need to work out the different state sets for
|
# Now we need to work out the different state sets for
|
||||||
# each state extremities
|
# each state extremities
|
||||||
state_sets = []
|
state_sets = []
|
||||||
|
state_groups = set()
|
||||||
missing_event_ids = []
|
missing_event_ids = []
|
||||||
was_updated = False
|
was_updated = False
|
||||||
for event_id in new_latest_event_ids:
|
for event_id in new_latest_event_ids:
|
||||||
@ -437,9 +438,17 @@ class EventsStore(SQLBaseStore):
|
|||||||
if event_id == ev.event_id:
|
if event_id == ev.event_id:
|
||||||
if ctx.current_state_ids is None:
|
if ctx.current_state_ids is None:
|
||||||
raise Exception("Unknown current state")
|
raise Exception("Unknown current state")
|
||||||
|
|
||||||
|
# If we've akready seen the state group don't bother adding
|
||||||
|
# it to the state sets again
|
||||||
|
if ctx.state_group not in state_groups:
|
||||||
state_sets.append(ctx.current_state_ids)
|
state_sets.append(ctx.current_state_ids)
|
||||||
if ctx.delta_ids or hasattr(ev, "state_key"):
|
if ctx.delta_ids or hasattr(ev, "state_key"):
|
||||||
was_updated = True
|
was_updated = True
|
||||||
|
if ctx.state_group:
|
||||||
|
# Add this as a seen state group (if it has a state
|
||||||
|
# group)
|
||||||
|
state_groups.add(ctx.state_group)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# If we couldn't find it, then we'll need to pull
|
# If we couldn't find it, then we'll need to pull
|
||||||
@ -453,14 +462,20 @@ class EventsStore(SQLBaseStore):
|
|||||||
missing_event_ids,
|
missing_event_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
groups = set(event_to_groups.itervalues())
|
groups = set(event_to_groups.itervalues()) - state_groups
|
||||||
group_to_state = yield self._get_state_for_groups(groups)
|
|
||||||
|
|
||||||
|
if groups:
|
||||||
|
group_to_state = yield self._get_state_for_groups(groups)
|
||||||
state_sets.extend(group_to_state.itervalues())
|
state_sets.extend(group_to_state.itervalues())
|
||||||
|
|
||||||
if not new_latest_event_ids:
|
if not new_latest_event_ids:
|
||||||
current_state = {}
|
current_state = {}
|
||||||
elif was_updated:
|
elif was_updated:
|
||||||
|
if len(state_sets) == 1:
|
||||||
|
# If there is only one state set, then we know what the current
|
||||||
|
# state is.
|
||||||
|
current_state = state_sets[0]
|
||||||
|
else:
|
||||||
# We work out the current state by passing the state sets to the
|
# We work out the current state by passing the state sets to the
|
||||||
# state resolution algorithm. It may ask for some events, including
|
# state resolution algorithm. It may ask for some events, including
|
||||||
# the events we have yet to persist, so we need a slightly more
|
# the events we have yet to persist, so we need a slightly more
|
||||||
|
Loading…
Reference in New Issue
Block a user