diff options
author | Erik Johnston <erik@matrix.org> | 2014-11-06 17:15:09 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-11-07 10:53:38 +0000 |
commit | 46de65cab9e449589e49b6cf7d37d4921363d934 (patch) | |
tree | a2ee173866eacb6117196585eca9804aa321f897 /synapse | |
parent | Amalgamate all power levels. (diff) | |
download | synapse-46de65cab9e449589e49b6cf7d37d4921363d934.tar.xz |
Don't query the DB for user power levels
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/state.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/synapse/state.py b/synapse/state.py index 97a8160a33..e2fd48bdae 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -18,6 +18,7 @@ from twisted.internet import defer from synapse.util.logutils import log_function from synapse.util.async import run_on_reactor +from synapse.api.events.room import RoomPowerLevelsEvent from collections import namedtuple @@ -141,21 +142,26 @@ class StateHandler(object): defer.returnValue(new_state) + def _get_power_level_from_event_state(self, event, user_id): + key = (RoomPowerLevelsEvent.TYPE, "", ) + power_level_event = event.old_state_events.get(key) + level = None + if power_level_event: + level = power_level_event.content.get("users", {}).get(user_id) + if not level: + level = power_level_event.content.get("users_default", 0) + + return level + @defer.inlineCallbacks @log_function def _resolve_state_events(self, events): curr_events = events - new_powers_deferreds = [] - for e in curr_events: - new_powers_deferreds.append( - self.store.get_power_level(e.room_id, e.user_id) - ) - - new_powers = yield defer.gatherResults( - new_powers_deferreds, - consumeErrors=True - ) + new_powers = [ + self._get_power_level_from_event_state(e, e.user_id) + for e in curr_events + ] new_powers = [ int(p) if p else 0 for p in new_powers |