diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index be9d1d8c41..5ba6c257c7 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -18,6 +18,7 @@ import logging from twisted.internet import defer, reactor from synapse.api.errors import SynapseError, AuthError, CodeMessageException +from synapse.util.logcontext import run_in_background from synapse.types import UserID, get_domain_from_id from ._base import BaseHandler @@ -205,8 +206,10 @@ class ProfileHandler(BaseHandler): if new_displayname == '': new_displayname = None + new_batchnum = (yield self.store.get_latest_profile_replication_batch_number()) + 1 + yield self.store.set_profile_displayname( - target_user.localpart, new_displayname + target_user.localpart, new_displayname, new_batchnum ) if self.hs.config.user_directory_search_all_users: @@ -217,6 +220,9 @@ class ProfileHandler(BaseHandler): yield self._update_join_states(requester, target_user) + # start a profile replication push + run_in_background(self._replicate_profiles) + @defer.inlineCallbacks def get_avatar_url(self, target_user): if self.hs.is_mine(target_user): @@ -255,8 +261,10 @@ class ProfileHandler(BaseHandler): if not by_admin and target_user != requester.user: raise AuthError(400, "Cannot set another user's avatar_url") + new_batchnum = yield self.store.get_latest_profile_replication_batch_number() + 1 + yield self.store.set_profile_avatar_url( - target_user.localpart, new_avatar_url + target_user.localpart, new_avatar_url, new_batchnum, ) if self.hs.config.user_directory_search_all_users: @@ -267,6 +275,9 @@ class ProfileHandler(BaseHandler): yield self._update_join_states(requester, target_user) + # start a profile replication push + run_in_background(self._replicate_profiles) + @defer.inlineCallbacks def on_profile_query(self, args): user = UserID.from_string(args["user_id"]) diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index cfc4a0606e..7b01f81d3d 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -64,11 +64,14 @@ class ProfileStore(SQLBaseStore): desc="get_profile_displayname", ) - def set_profile_displayname(self, user_localpart, new_displayname): + def set_profile_displayname(self, user_localpart, new_displayname, batchnum): return self._simple_update_one( table="profiles", keyvalues={"user_id": user_localpart}, - updatevalues={"displayname": new_displayname}, + updatevalues={ + "displayname": new_displayname, + "batch": batchnum, + }, desc="set_profile_displayname", ) @@ -80,11 +83,14 @@ class ProfileStore(SQLBaseStore): desc="get_profile_avatar_url", ) - def set_profile_avatar_url(self, user_localpart, new_avatar_url): + def set_profile_avatar_url(self, user_localpart, new_avatar_url, batchnum): return self._simple_update_one( table="profiles", keyvalues={"user_id": user_localpart}, - updatevalues={"avatar_url": new_avatar_url}, + updatevalues={ + "avatar_url": new_avatar_url, + "batch": batchnum, + }, desc="set_profile_avatar_url", )