summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/profile.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index 9af2e8f869..8b349f6ad6 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -25,6 +25,7 @@ from synapse.api.errors import (
     SynapseError,
 )
 from synapse.metrics.background_process_metrics import run_as_background_process
+from synapse.replication.http.profile import ReplicationHandleProfileChangeRestServlet
 from synapse.types import UserID, get_domain_from_id
 
 from ._base import BaseHandler
@@ -32,12 +33,12 @@ from ._base import BaseHandler
 logger = logging.getLogger(__name__)
 
 
-class ProfileHandler(BaseHandler):
+class WorkerProfileHandler(BaseHandler):
     PROFILE_UPDATE_MS = 60 * 1000
     PROFILE_UPDATE_EVERY_MS = 24 * 60 * 60 * 1000
 
     def __init__(self, hs):
-        super(ProfileHandler, self).__init__(hs)
+        super(WorkerProfileHandler, self).__init__(hs)
 
         self.federation = hs.get_federation_client()
         hs.get_federation_registry().register_query_handler(
@@ -46,10 +47,9 @@ class ProfileHandler(BaseHandler):
 
         self.user_directory_handler = hs.get_user_directory_handler()
 
-        if hs.config.worker_app is None:
-            self.clock.looping_call(
-                self._start_update_remote_profile_cache, self.PROFILE_UPDATE_MS,
-            )
+        self._notify_master_profile_change = (
+            ReplicationHandleProfileChangeRestServlet.make_client(hs)
+        )
 
     @defer.inlineCallbacks
     def get_profile(self, user_id):
@@ -166,10 +166,16 @@ class ProfileHandler(BaseHandler):
         )
 
         if self.hs.config.user_directory_search_all_users:
-            profile = yield self.store.get_profileinfo(target_user.localpart)
-            yield self.user_directory_handler.handle_local_profile_change(
-                target_user.to_string(), profile
-            )
+            if self.hs.config.worker_app is None:
+                profile = yield self.store.get_profileinfo(target_user.localpart)
+                yield self.user_directory_handler.handle_local_profile_change(
+                    target_user.to_string(), profile
+                )
+            else:
+                yield self._notify_master_profile_change(
+                    requester=requester,
+                    user_id=target_user.to_string(),
+                )
 
         yield self._update_join_states(requester, target_user)
 
@@ -219,11 +225,16 @@ class ProfileHandler(BaseHandler):
             target_user.localpart, new_avatar_url
         )
 
-        if self.hs.config.user_directory_search_all_users:
+        if self.hs.config.worker_app is None:
             profile = yield self.store.get_profileinfo(target_user.localpart)
             yield self.user_directory_handler.handle_local_profile_change(
                 target_user.to_string(), profile
             )
+        else:
+            yield self._notify_master_profile_change(
+                requester=requester,
+                user_id=target_user.to_string(),
+            )
 
         yield self._update_join_states(requester, target_user)
 
@@ -282,6 +293,18 @@ class ProfileHandler(BaseHandler):
                     room_id, str(e.message)
                 )
 
+
+class MasterProfileHandler(WorkerProfileHandler):
+    PROFILE_UPDATE_MS = 60 * 1000
+    PROFILE_UPDATE_EVERY_MS = 24 * 60 * 60 * 1000
+
+    def __init__(self, hs):
+        super(MasterProfileHandler, self).__init__(hs)
+
+        self.clock.looping_call(
+            self._start_update_remote_profile_cache, self.PROFILE_UPDATE_MS,
+        )
+
     def _start_update_remote_profile_cache(self):
         return run_as_background_process(
             "Update remote profile", self._update_remote_profile_cache,