diff --git a/synapse/storage/databases/main/stats.py b/synapse/storage/databases/main/stats.py
index 97c4dc2603..2962317ea2 100644
--- a/synapse/storage/databases/main/stats.py
+++ b/synapse/storage/databases/main/stats.py
@@ -697,7 +697,7 @@ class StatsStore(StateDeltasStore):
txn: LoggingTransaction,
) -> Tuple[List[JsonDict], int]:
filters = []
- args = [self.hs.config.server.server_name]
+ args = []
if search_term:
filters.append("(lmr.user_id LIKE ? OR displayname LIKE ?)")
@@ -733,7 +733,7 @@ class StatsStore(StateDeltasStore):
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(
diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py
index 924022c95c..8fa24e2870 100644
--- a/synapse/storage/databases/main/user_directory.py
+++ b/synapse/storage/databases/main/user_directory.py
@@ -414,18 +414,18 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore):
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"],
)
|