mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-19 11:34:17 -05:00
Fix user dir to not assume existence of user
This commit is contained in:
parent
fdca6e36ee
commit
6fd7e6db3d
@ -151,37 +151,52 @@ class UserDirectoryStore(SQLBaseStore):
|
|||||||
|
|
||||||
def update_profile_in_user_dir(self, user_id, display_name, avatar_url):
|
def update_profile_in_user_dir(self, user_id, display_name, avatar_url):
|
||||||
def _update_profile_in_user_dir_txn(txn):
|
def _update_profile_in_user_dir_txn(txn):
|
||||||
self._simple_update_one_txn(
|
new_entry = self._simple_upsert_txn(
|
||||||
txn,
|
txn,
|
||||||
table="user_directory",
|
table="user_directory",
|
||||||
keyvalues={"user_id": user_id},
|
keyvalues={"user_id": user_id},
|
||||||
updatevalues={"display_name": display_name, "avatar_url": avatar_url},
|
values={"display_name": display_name, "avatar_url": avatar_url},
|
||||||
|
lock=False, # We're only inserter
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(self.database_engine, PostgresEngine):
|
if isinstance(self.database_engine, PostgresEngine):
|
||||||
# We weight the loclpart most highly, then display name and finally
|
# We weight the loclpart most highly, then display name and finally
|
||||||
# server name
|
# server name
|
||||||
sql = """
|
if new_entry:
|
||||||
UPDATE user_directory_search
|
sql = """
|
||||||
SET vector = setweight(to_tsvector('english', ?), 'A')
|
INSERT INTO user_directory_search(user_id, vector)
|
||||||
|| setweight(to_tsvector('english', ?), 'D')
|
VALUES (?,
|
||||||
|| setweight(to_tsvector('english', COALESCE(?, '')), 'B')
|
setweight(to_tsvector('english', ?), 'A')
|
||||||
WHERE user_id = ?
|
|| setweight(to_tsvector('english', ?), 'D')
|
||||||
"""
|
|| setweight(to_tsvector('english', COALESCE(?, '')), 'B')
|
||||||
args = (
|
)
|
||||||
get_localpart_from_id(user_id), get_domain_from_id(user_id),
|
"""
|
||||||
display_name,
|
args = (
|
||||||
user_id,
|
user_id,
|
||||||
)
|
get_localpart_from_id(user_id), get_domain_from_id(user_id),
|
||||||
|
display_name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
sql = """
|
||||||
|
UPDATE user_directory_search
|
||||||
|
SET vector = setweight(to_tsvector('english', ?), 'A')
|
||||||
|
|| setweight(to_tsvector('english', ?), 'D')
|
||||||
|
|| setweight(to_tsvector('english', COALESCE(?, '')), 'B')
|
||||||
|
WHERE user_id = ?
|
||||||
|
"""
|
||||||
|
args = (
|
||||||
|
get_localpart_from_id(user_id), get_domain_from_id(user_id),
|
||||||
|
display_name,
|
||||||
|
user_id,
|
||||||
|
)
|
||||||
elif isinstance(self.database_engine, Sqlite3Engine):
|
elif isinstance(self.database_engine, Sqlite3Engine):
|
||||||
sql = """
|
value = "%s %s" % (user_id, display_name,) if display_name else user_id
|
||||||
UPDATE user_directory_search
|
self._simple_upsert_txn(
|
||||||
set value = ?
|
txn,
|
||||||
WHERE user_id = ?
|
table="user_directory_search",
|
||||||
"""
|
keyvalues={"user_id": user_id},
|
||||||
args = (
|
values={"value": value},
|
||||||
"%s %s" % (user_id, display_name,) if display_name else user_id,
|
lock=False, # We're only inserter
|
||||||
user_id,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# This should be unreachable.
|
# This should be unreachable.
|
||||||
|
Loading…
Reference in New Issue
Block a user