Time evaluator_for_event

erikj/timings
Erik Johnston 2016-05-31 13:03:48 +01:00
parent d375e0038e
commit 05f2c86891
1 changed files with 23 additions and 15 deletions

View File

@ -23,6 +23,7 @@ from .push_rule_evaluator import PushRuleEvaluatorForEvent
from synapse.api.constants import EventTypes
from synapse.visibility import filter_events_for_clients
from synapse.util.logutils import log_duration
logger = logging.getLogger(__name__)
@ -75,6 +76,7 @@ def evaluator_for_event(event, hs, store):
# users in the room who have pushers need to get push rules run because
# that's how their pushers work
with log_duration("get_users_with_pushers_in_room"):
users_with_pushers = yield store.get_users_with_pushers_in_room(room_id)
# We also will want to generate notifs for other people in the room so
@ -82,12 +84,16 @@ def evaluator_for_event(event, hs, store):
# generating them for bot / AS users etc, we only do so for people who've
# sent a read receipt into the room.
with log_duration("get_users_in_room"):
all_in_room = yield store.get_users_in_room(room_id)
with log_duration("all_in_room"):
all_in_room = set(all_in_room)
with log_duration("get_receipts_for_room"):
receipts = yield store.get_receipts_for_room(room_id, "m.read")
# any users with pushers must be ours: they have pushers
with log_duration("get_mine_pushers"):
user_ids = set(users_with_pushers)
for r in receipts:
if hs.is_mine_id(r['user_id']) and r['user_id'] in all_in_room:
@ -95,6 +101,7 @@ def evaluator_for_event(event, hs, store):
# if this event is an invite event, we may need to run rules for the user
# who's been invited, otherwise they won't get told they've been invited
with log_duration("add_invite"):
if event.type == 'm.room.member' and event.content['membership'] == 'invite':
invited_user = event.state_key
if invited_user and hs.is_mine_id(invited_user):
@ -104,6 +111,7 @@ def evaluator_for_event(event, hs, store):
user_ids = list(user_ids)
with log_duration("_get_rules"):
rules_by_user = yield _get_rules(room_id, user_ids, store)
defer.returnValue(BulkPushRuleEvaluator(