summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2016-08-17 11:30:16 +0100
committerGitHub <noreply@github.com>2016-08-17 11:30:16 +0100
commit92d39126d70477da65c478c1ffc5a6ef124833d6 (patch)
tree0cd796afb2df09502471435c77ff772485474045
parentMerge pull request #1016 from matrix-org/erikj/short_circuit_cache (diff)
parentUpdate unit tests (diff)
downloadsynapse-92d39126d70477da65c478c1ffc5a6ef124833d6.tar.xz
Merge pull request #1017 from matrix-org/erikj/appservice_measure
Measure notify_interested_services
-rw-r--r--synapse/handlers/appservice.py41
-rw-r--r--tests/handlers/test_appservice.py2
2 files changed, 24 insertions, 19 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index 051ccdb380..48feae07b5 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -17,6 +17,7 @@ from twisted.internet import defer
 
 from synapse.api.constants import EventTypes
 from synapse.appservice import ApplicationService
+from synapse.util.metrics import Measure
 
 import logging
 
@@ -42,6 +43,7 @@ class ApplicationServicesHandler(object):
         self.appservice_api = hs.get_application_service_api()
         self.scheduler = hs.get_application_service_scheduler()
         self.started_scheduler = False
+        self.clock = hs.get_clock()
 
     @defer.inlineCallbacks
     def notify_interested_services(self, event):
@@ -53,25 +55,26 @@ class ApplicationServicesHandler(object):
         Args:
             event(Event): The event to push out to interested services.
         """
-        # Gather interested services
-        services = yield self._get_services_for_event(event)
-        if len(services) == 0:
-            return  # no services need notifying
-
-        # 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
-        # user queries need to be made BEFORE pushing the event.
-        yield self._check_user_exists(event.sender)
-        if event.type == EventTypes.Member:
-            yield self._check_user_exists(event.state_key)
-
-        if not self.started_scheduler:
-            self.scheduler.start().addErrback(log_failure)
-            self.started_scheduler = True
-
-        # Fork off pushes to these services
-        for service in services:
-            self.scheduler.submit_event_for_as(service, event)
+        with Measure(self.clock, "notify_interested_services"):
+            # Gather interested services
+            services = yield self._get_services_for_event(event)
+            if len(services) == 0:
+                return  # no services need notifying
+
+            # 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
+            # user queries need to be made BEFORE pushing the event.
+            yield self._check_user_exists(event.sender)
+            if event.type == EventTypes.Member:
+                yield self._check_user_exists(event.state_key)
+
+            if not self.started_scheduler:
+                self.scheduler.start().addErrback(log_failure)
+                self.started_scheduler = True
+
+            # Fork off pushes to these services
+            for service in services:
+                self.scheduler.submit_event_for_as(service, event)
 
     @defer.inlineCallbacks
     def query_user_exists(self, user_id):
diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py
index a884c95f8d..3116951472 100644
--- a/tests/handlers/test_appservice.py
+++ b/tests/handlers/test_appservice.py
@@ -15,6 +15,7 @@
 
 from twisted.internet import defer
 from .. import unittest
+from tests.utils import MockClock
 
 from synapse.handlers.appservice import ApplicationServicesHandler
 
@@ -32,6 +33,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         hs.get_datastore = Mock(return_value=self.mock_store)
         hs.get_application_service_api = Mock(return_value=self.mock_as_api)
         hs.get_application_service_scheduler = Mock(return_value=self.mock_scheduler)
+        hs.get_clock.return_value = MockClock()
         self.handler = ApplicationServicesHandler(hs)
 
     @defer.inlineCallbacks