From 32e4420a6678f1cfa4a3e488cff2d219ca326950 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 3 May 2018 04:20:25 +0100 Subject: improve mxid & displayname selection for register_mxid_from_3pid * [x] strip invalid characters from generated mxid * [x] append numbers to disambiguate clashing mxids * [x] generate displayanames from 3pids using a dodgy heuristic * [x] get rid of the create_profile_with_localpart and instead explicitly set displaynames so they propagate correctly --- synapse/storage/registration.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'synapse/storage') diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py index 6b557ca0cf..384c9977c1 100644 --- a/synapse/storage/registration.py +++ b/synapse/storage/registration.py @@ -128,7 +128,7 @@ class RegistrationStore(RegistrationWorkerStore, def register(self, user_id, token=None, password_hash=None, was_guest=False, make_guest=False, appservice_id=None, - create_profile_with_localpart=None, admin=False): + admin=False): """Attempts to register an account. Args: @@ -142,8 +142,6 @@ class RegistrationStore(RegistrationWorkerStore, make_guest (boolean): True if the the new user should be guest, false to add a regular user account. appservice_id (str): The ID of the appservice registering the user. - create_profile_with_localpart (str): Optionally create a profile for - the given localpart. Raises: StoreError if the user_id could not be registered. """ @@ -156,7 +154,6 @@ class RegistrationStore(RegistrationWorkerStore, was_guest, make_guest, appservice_id, - create_profile_with_localpart, admin ) @@ -169,7 +166,6 @@ class RegistrationStore(RegistrationWorkerStore, was_guest, make_guest, appservice_id, - create_profile_with_localpart, admin, ): now = int(self.clock.time()) @@ -234,14 +230,6 @@ class RegistrationStore(RegistrationWorkerStore, (next_id, user_id, token,) ) - if create_profile_with_localpart: - # set a default displayname serverside to avoid ugly race - # between auto-joins and clients trying to set displaynames - txn.execute( - "INSERT INTO profiles(user_id, displayname) VALUES (?,?)", - (create_profile_with_localpart, create_profile_with_localpart) - ) - self._invalidate_cache_and_stream( txn, self.get_user_by_id, (user_id,) ) -- cgit 1.5.1 From fb47ce3e6af06c36bd8c430d79801307814d5909 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 4 May 2018 01:46:26 +0100 Subject: make set_profile_* an upsert rather than update, now create_profile is gone --- synapse/storage/profile.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'synapse/storage') diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index fcf3af7e5b..da1db0ebae 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -125,33 +125,28 @@ class ProfileWorkerStore(SQLBaseStore): class ProfileStore(ProfileWorkerStore): - def create_profile(self, user_localpart): - return self._simple_insert( - table="profiles", - values={"user_id": user_localpart}, - desc="create_profile", - ) - def set_profile_displayname(self, user_localpart, new_displayname, batchnum): - return self._simple_update_one( + return self._simple_upsert( table="profiles", keyvalues={"user_id": user_localpart}, - updatevalues={ + values={ "displayname": new_displayname, "batch": batchnum, }, desc="set_profile_displayname", + lock=False # we can do this because user_id has a unique index ) def set_profile_avatar_url(self, user_localpart, new_avatar_url, batchnum): - return self._simple_update_one( + return self._simple_upsert( table="profiles", keyvalues={"user_id": user_localpart}, - updatevalues={ + values={ "avatar_url": new_avatar_url, "batch": batchnum, }, desc="set_profile_avatar_url", + lock=False # we can do this because user_id has a unique index ) def add_remote_profile_cache(self, user_id, displayname, avatar_url): -- cgit 1.5.1