From 46de65cab9e449589e49b6cf7d37d4921363d934 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 6 Nov 2014 17:15:09 +0000 Subject: Don't query the DB for user power levels --- synapse/state.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'synapse/state.py') 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 -- cgit 1.4.1