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,36 +76,43 @@ 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
users_with_pushers = yield store.get_users_with_pushers_in_room(room_id)
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
# their unread countss are correct in the event stream, but to avoid
# generating them for bot / AS users etc, we only do so for people who've
# sent a read receipt into the room.
all_in_room = yield store.get_users_in_room(room_id)
all_in_room = set(all_in_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)
receipts = yield store.get_receipts_for_room(room_id, "m.read")
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
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:
user_ids.add(r['user_id'])
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:
user_ids.add(r['user_id'])
# 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
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):
has_pusher = yield store.user_has_pusher(invited_user)
if has_pusher:
user_ids.add(invited_user)
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):
has_pusher = yield store.user_has_pusher(invited_user)
if has_pusher:
user_ids.add(invited_user)
user_ids = list(user_ids)
rules_by_user = yield _get_rules(room_id, user_ids, store)
with log_duration("_get_rules"):
rules_by_user = yield _get_rules(room_id, user_ids, store)
defer.returnValue(BulkPushRuleEvaluator(
room_id, rules_by_user, user_ids, store