Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Actually stop reading from column user_id of tables profiles (mat…
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay authored and Fizzadar committed Aug 31, 2023
1 parent 4aac077 commit 94b1bb4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.d/15955.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop reading from column `user_id` of table `profiles`.
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def get_users_paginate_txn(
txn: LoggingTransaction,
) -> Tuple[List[JsonDict], int]:
filters = []
args = [self.hs.config.server.server_name]
args: list = []

# Set ordering
order_by_column = UserSortOrder(order_by).value
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_users_paginate_txn(

sql_base = f"""
FROM users as u
LEFT JOIN profiles AS p ON u.name = '@' || p.user_id || ':' || ?
LEFT JOIN profiles AS p ON u.name = p.full_user_id
LEFT JOIN erased_users AS eu ON u.name = eu.user_id
{where_clause}
"""
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def get_users_media_usage_paginate_txn(
txn: LoggingTransaction,
) -> Tuple[List[JsonDict], int]:
filters = []
args = [self.hs.config.server.server_name]
args: list = []

if search_term:
filters.append("(lmr.user_id LIKE ? OR displayname LIKE ?)")
Expand Down Expand Up @@ -733,7 +733,7 @@ def get_users_media_usage_paginate_txn(

sql_base = """
FROM local_media_repository as lmr
LEFT JOIN profiles AS p ON lmr.user_id = '@' || p.user_id || ':' || ?
LEFT JOIN profiles AS p ON lmr.user_id = p.full_user_id
{}
GROUP BY lmr.user_id, displayname
""".format(
Expand Down
13 changes: 6 additions & 7 deletions synapse/storage/databases/main/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,22 @@ def _populate_user_directory_process_users_txn(
txn, users_to_work_on
)

# Next fetch their profiles. Note that the `user_id` here is the
# *localpart*, and that not all users have profiles.
# Next fetch their profiles. Note that not all users have profiles.
profile_rows = self.db_pool.simple_select_many_txn(
txn,
table="profiles",
column="user_id",
iterable=[get_localpart_from_id(u) for u in users_to_insert],
column="full_user_id",
iterable=list(users_to_insert),
retcols=(
"user_id",
"full_user_id",
"displayname",
"avatar_url",
),
keyvalues={},
)
profiles = {
f"@{row['user_id']}:{self.server_name}": _UserDirProfile(
f"@{row['user_id']}:{self.server_name}",
row["full_user_id"]: _UserDirProfile(
row["full_user_id"],
row["displayname"],
row["avatar_url"],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ def test_deactivate_user_erase_true_no_profile(self) -> None:
# To test deactivation for users without a profile, we delete the profile information for our user.
self.get_success(
self.store.db_pool.simple_delete_one(
table="profiles", keyvalues={"user_id": "user"}
table="profiles", keyvalues={"full_user_id": "@user:test"}
)
)

Expand Down

0 comments on commit 94b1bb4

Please sign in to comment.