summary refs log tree commit diff
path: root/synapse/handlers/profile.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-08-06 14:46:17 +0100
committerErik Johnston <erik@matrix.org>2018-08-07 10:50:26 +0100
commit495cb100d127212d55a46c177706d732950e70be (patch)
tree1da492aa00c9177a1b6d8be5ba725a5c063f6f12 /synapse/handlers/profile.py
parentFix isort (diff)
downloadsynapse-495cb100d127212d55a46c177706d732950e70be.tar.xz
Allow profile changes to happen on workers
Diffstat (limited to 'synapse/handlers/profile.py')
-rw-r--r--synapse/handlers/profile.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index cb5c6d587e..a3bdb1830f 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -19,6 +19,7 @@ from twisted.internet import defer
 
 from synapse.api.errors import AuthError, CodeMessageException, 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
@@ -45,6 +46,10 @@ class ProfileHandler(BaseHandler):
                 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):
         target_user = UserID.from_string(user_id)
@@ -147,10 +152,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)
 
@@ -196,11 +207,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)