Measure notify_interested_services

This commit is contained in:
Erik Johnston 2016-08-17 11:12:29 +01:00
parent 949629291c
commit 62c5245c87

View file

@ -17,6 +17,7 @@ from twisted.internet import defer
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
from synapse.appservice import ApplicationService from synapse.appservice import ApplicationService
from synapse.util.metrics import Measure
import logging import logging
@ -42,6 +43,7 @@ class ApplicationServicesHandler(object):
self.appservice_api = hs.get_application_service_api() self.appservice_api = hs.get_application_service_api()
self.scheduler = hs.get_application_service_scheduler() self.scheduler = hs.get_application_service_scheduler()
self.started_scheduler = False self.started_scheduler = False
self.clock = hs.get_clock()
@defer.inlineCallbacks @defer.inlineCallbacks
def notify_interested_services(self, event): def notify_interested_services(self, event):
@ -53,25 +55,26 @@ class ApplicationServicesHandler(object):
Args: Args:
event(Event): The event to push out to interested services. event(Event): The event to push out to interested services.
""" """
# Gather interested services with Measure(self.clock, "notify_interested_services"):
services = yield self._get_services_for_event(event) # Gather interested services
if len(services) == 0: services = yield self._get_services_for_event(event)
return # no services need notifying if len(services) == 0:
return # no services need notifying
# Do we know this user exists? If not, poke the user query API for # Do we know this user exists? If not, poke the user query API for
# all services which match that user regex. This needs to block as these # all services which match that user regex. This needs to block as these
# user queries need to be made BEFORE pushing the event. # user queries need to be made BEFORE pushing the event.
yield self._check_user_exists(event.sender) yield self._check_user_exists(event.sender)
if event.type == EventTypes.Member: if event.type == EventTypes.Member:
yield self._check_user_exists(event.state_key) yield self._check_user_exists(event.state_key)
if not self.started_scheduler: if not self.started_scheduler:
self.scheduler.start().addErrback(log_failure) self.scheduler.start().addErrback(log_failure)
self.started_scheduler = True self.started_scheduler = True
# Fork off pushes to these services # Fork off pushes to these services
for service in services: for service in services:
self.scheduler.submit_event_for_as(service, event) self.scheduler.submit_event_for_as(service, event)
@defer.inlineCallbacks @defer.inlineCallbacks
def query_user_exists(self, user_id): def query_user_exists(self, user_id):