mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-15 22:42:23 +01:00
Fix bug where we /always/ created a new state group
This commit is contained in:
parent
ed8b7d400c
commit
5ff0bfb81d
3 changed files with 41 additions and 30 deletions
|
@ -448,8 +448,9 @@ class FederationHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
if state_groups:
|
if state_groups:
|
||||||
|
_, state = state_groups.items().pop()
|
||||||
results = {
|
results = {
|
||||||
(e.type, e.state_key): e for e in state_groups[0].state
|
(e.type, e.state_key): e for e in state
|
||||||
}
|
}
|
||||||
|
|
||||||
event = yield self.store.get_event(event_id)
|
event = yield self.store.get_event(event_id)
|
||||||
|
|
|
@ -42,9 +42,6 @@ class StateHandler(object):
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self._replication = hs.get_replication_layer()
|
|
||||||
self.server_name = hs.hostname
|
|
||||||
self.hs = hs
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
|
@ -71,9 +68,10 @@ class StateHandler(object):
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
new_state = yield self.resolve_state_groups(
|
ids = [e for e, _ in event.prev_events]
|
||||||
[e for e, _ in event.prev_events]
|
|
||||||
)
|
ret = yield self.resolve_state_groups(ids)
|
||||||
|
state_group, new_state = ret
|
||||||
|
|
||||||
event.old_state_events = copy.deepcopy(new_state)
|
event.old_state_events = copy.deepcopy(new_state)
|
||||||
|
|
||||||
|
@ -82,6 +80,10 @@ class StateHandler(object):
|
||||||
if key in new_state:
|
if key in new_state:
|
||||||
event.replaces_state = new_state[key].event_id
|
event.replaces_state = new_state[key].event_id
|
||||||
new_state[key] = event
|
new_state[key] = event
|
||||||
|
elif state_group:
|
||||||
|
event.state_group = state_group
|
||||||
|
event.state_events = new_state
|
||||||
|
defer.returnValue(False)
|
||||||
|
|
||||||
event.state_group = None
|
event.state_group = None
|
||||||
event.state_events = new_state
|
event.state_events = new_state
|
||||||
|
@ -100,7 +102,7 @@ class StateHandler(object):
|
||||||
res = yield self.resolve_state_groups(event_ids)
|
res = yield self.resolve_state_groups(event_ids)
|
||||||
|
|
||||||
if event_type:
|
if event_type:
|
||||||
defer.returnValue(res.get((event_type, state_key)))
|
defer.returnValue(res[1].get((event_type, state_key)))
|
||||||
return
|
return
|
||||||
|
|
||||||
defer.returnValue(res.values())
|
defer.returnValue(res.values())
|
||||||
|
@ -112,9 +114,18 @@ class StateHandler(object):
|
||||||
event_ids
|
event_ids
|
||||||
)
|
)
|
||||||
|
|
||||||
|
group_names = set(state_groups.keys())
|
||||||
|
if len(group_names) == 1:
|
||||||
|
name, state_list = state_groups.items().pop()
|
||||||
|
state = {
|
||||||
|
(e.type, e.state_key): e
|
||||||
|
for e in state_list
|
||||||
|
}
|
||||||
|
defer.returnValue((name, state))
|
||||||
|
|
||||||
state = {}
|
state = {}
|
||||||
for group in state_groups:
|
for group, g_state in state_groups.items():
|
||||||
for s in group.state:
|
for s in g_state:
|
||||||
state.setdefault(
|
state.setdefault(
|
||||||
(s.type, s.state_key),
|
(s.type, s.state_key),
|
||||||
{}
|
{}
|
||||||
|
@ -135,25 +146,29 @@ class StateHandler(object):
|
||||||
new_state = {}
|
new_state = {}
|
||||||
new_state.update(unconflicted_state)
|
new_state.update(unconflicted_state)
|
||||||
for key, events in conflicted_state.items():
|
for key, events in conflicted_state.items():
|
||||||
new_state[key] = yield self._resolve_state_events(events)
|
new_state[key] = self._resolve_state_events(events)
|
||||||
except:
|
except:
|
||||||
logger.exception("Failed to resolve state")
|
logger.exception("Failed to resolve state")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
defer.returnValue(new_state)
|
defer.returnValue((None, new_state))
|
||||||
|
|
||||||
def _get_power_level_from_event_state(self, event, user_id):
|
def _get_power_level_from_event_state(self, event, user_id):
|
||||||
|
if hasattr(event, "old_state_events") and event.old_state_events:
|
||||||
key = (RoomPowerLevelsEvent.TYPE, "", )
|
key = (RoomPowerLevelsEvent.TYPE, "", )
|
||||||
power_level_event = event.old_state_events.get(key)
|
power_level_event = event.old_state_events.get(key)
|
||||||
level = None
|
level = None
|
||||||
if power_level_event:
|
if power_level_event:
|
||||||
level = power_level_event.content.get("users", {}).get(user_id)
|
level = power_level_event.content.get("users", {}).get(
|
||||||
|
user_id
|
||||||
|
)
|
||||||
if not level:
|
if not level:
|
||||||
level = power_level_event.content.get("users_default", 0)
|
level = power_level_event.content.get("users_default", 0)
|
||||||
|
|
||||||
return level
|
return level
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
@log_function
|
@log_function
|
||||||
def _resolve_state_events(self, events):
|
def _resolve_state_events(self, events):
|
||||||
curr_events = events
|
curr_events = events
|
||||||
|
@ -177,10 +192,10 @@ class StateHandler(object):
|
||||||
if not curr_events:
|
if not curr_events:
|
||||||
raise RuntimeError("Max didn't get a max?")
|
raise RuntimeError("Max didn't get a max?")
|
||||||
elif len(curr_events) == 1:
|
elif len(curr_events) == 1:
|
||||||
defer.returnValue(curr_events[0])
|
return curr_events[0]
|
||||||
|
|
||||||
# TODO: For now, just choose the one with the largest event_id.
|
# TODO: For now, just choose the one with the largest event_id.
|
||||||
defer.returnValue(
|
return (
|
||||||
sorted(
|
sorted(
|
||||||
curr_events,
|
curr_events,
|
||||||
key=lambda e: hashlib.sha1(
|
key=lambda e: hashlib.sha1(
|
||||||
|
|
|
@ -16,11 +16,6 @@
|
||||||
from ._base import SQLBaseStore
|
from ._base import SQLBaseStore
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
|
|
||||||
StateGroup = namedtuple("StateGroup", ("group", "state"))
|
|
||||||
|
|
||||||
|
|
||||||
class StateStore(SQLBaseStore):
|
class StateStore(SQLBaseStore):
|
||||||
|
|
||||||
|
@ -37,7 +32,7 @@ class StateStore(SQLBaseStore):
|
||||||
if group:
|
if group:
|
||||||
groups.add(group)
|
groups.add(group)
|
||||||
|
|
||||||
res = []
|
res = {}
|
||||||
for group in groups:
|
for group in groups:
|
||||||
state_ids = yield self._simple_select_onecol(
|
state_ids = yield self._simple_select_onecol(
|
||||||
table="state_groups_state",
|
table="state_groups_state",
|
||||||
|
@ -53,7 +48,7 @@ class StateStore(SQLBaseStore):
|
||||||
if s:
|
if s:
|
||||||
state.append(s)
|
state.append(s)
|
||||||
|
|
||||||
res.append(StateGroup(group, state))
|
res[group] = state
|
||||||
|
|
||||||
defer.returnValue(res)
|
defer.returnValue(res)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue