mirror of
https://github.com/element-hq/synapse
synced 2024-09-05 08:20:05 +00:00
Only construct sets when necessary
This commit is contained in:
parent
a8594fd19f
commit
c6064a7ba6
1 changed files with 19 additions and 14 deletions
|
@ -453,22 +453,27 @@ def _seperate(state_sets):
|
||||||
unconflicted_state = dict(state_sets[0])
|
unconflicted_state = dict(state_sets[0])
|
||||||
conflicted_state = {}
|
conflicted_state = {}
|
||||||
|
|
||||||
full_states = defaultdict(
|
|
||||||
set,
|
|
||||||
{k: set((v,)) for k, v in state_sets[0].iteritems()}
|
|
||||||
)
|
|
||||||
|
|
||||||
for state_set in state_sets[1:]:
|
for state_set in state_sets[1:]:
|
||||||
for key, value in state_set.iteritems():
|
for key, value in state_set.iteritems():
|
||||||
ls = full_states[key]
|
# Check if there is an unconflicted entry for the state key.
|
||||||
if not ls:
|
unconflicted_value = unconflicted_state.get(key)
|
||||||
ls.add(value)
|
if unconflicted_value is None:
|
||||||
unconflicted_state[key] = value
|
# There isn't an unconflicted entry so check if there is a
|
||||||
elif value not in ls:
|
# conflicted entry.
|
||||||
ls.add(value)
|
ls = conflicted_state.get(key)
|
||||||
if len(ls) == 2:
|
if ls is None:
|
||||||
conflicted_state[key] = ls
|
# There wasn't a conflicted entry so haven't seen this key before.
|
||||||
unconflicted_state.pop(key, None)
|
# Therefore it isn't conflicted yet.
|
||||||
|
unconflicted_state[key] = value
|
||||||
|
else:
|
||||||
|
# This key is already conflicted, add our value to the conflict set.
|
||||||
|
ls.add(value)
|
||||||
|
elif unconflicted_value != value:
|
||||||
|
# If the unconflicted value is not the same as our value then we
|
||||||
|
# have a new conflict. So move the key from the unconflicted_state
|
||||||
|
# to the conflicted state.
|
||||||
|
conflicted_state[key] = {value, unconflicted_value}
|
||||||
|
unconflicted_state.pop(key, None)
|
||||||
|
|
||||||
return unconflicted_state, conflicted_state
|
return unconflicted_state, conflicted_state
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue