diff options
author | Erik Johnston <erik@matrix.org> | 2015-02-13 14:32:17 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-02-13 14:32:17 +0000 |
commit | 2aa87305c02b2d75a2a6a1893782127ae9e328f8 (patch) | |
tree | 4f52989565dcfa53d184b28064bcc919bcbf6a4b /synapse/state.py | |
parent | Merge branch 'master' of github.com:matrix-org/synapse into develop (diff) | |
parent | pyflakes (diff) | |
download | synapse-2aa87305c02b2d75a2a6a1893782127ae9e328f8.tar.xz |
Merge pull request #71 from matrix-org/auth-conflict-res
When we see a difference in current state, actually use state conflict resolution algorithm
Diffstat (limited to 'synapse/state.py')
-rw-r--r-- | synapse/state.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/synapse/state.py b/synapse/state.py index 98aaa2be53..fe5f3dc84b 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -259,13 +259,37 @@ class StateHandler(object): defer.returnValue((name, state, prev_states)) + new_state, prev_states = self._resolve_events( + state_groups.values(), event_type, state_key + ) + + if self._state_cache is not None: + cache = _StateCacheEntry( + state=new_state, + state_group=None, + ts=self.clock.time_msec() + ) + + self._state_cache[frozenset(event_ids)] = cache + + defer.returnValue((None, new_state, prev_states)) + + def resolve_events(self, state_sets, event): + if event.is_state(): + return self._resolve_events( + state_sets, event.type, event.state_key + ) + else: + return self._resolve_events(state_sets) + + def _resolve_events(self, state_sets, event_type=None, state_key=""): state = {} - for group, g_state in state_groups.items(): - for s in g_state: + for st in state_sets: + for e in st: state.setdefault( - (s.type, s.state_key), + (e.type, e.state_key), {} - )[s.event_id] = s + )[e.event_id] = e unconflicted_state = { k: v.values()[0] for k, v in state.items() @@ -302,16 +326,7 @@ class StateHandler(object): new_state = unconflicted_state new_state.update(resolved_state) - if self._state_cache is not None: - cache = _StateCacheEntry( - state=new_state, - state_group=None, - ts=self.clock.time_msec() - ) - - self._state_cache[frozenset(event_ids)] = cache - - defer.returnValue((None, new_state, prev_states)) + return new_state, prev_states @log_function def _resolve_state_events(self, conflicted_state, auth_events): |