mirror of
https://github.com/element-hq/synapse.git
synced 2026-07-30 11:50:12 +00:00
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
57675ee36d
commit
3824af8778
@@ -145,7 +145,6 @@ class WriterLocations:
|
||||
device_lists: The instances that write to the device list stream.
|
||||
thread_subscriptions: The instances that write to the thread subscriptions
|
||||
stream.
|
||||
profile_updates: The instances that write to the profile updates stream.
|
||||
quarantined_media_changes: The instances that write to the quarantined media
|
||||
changes stream.
|
||||
"""
|
||||
|
||||
@@ -2416,10 +2416,15 @@ class SyncHandler:
|
||||
# user ID + field name + value, which ensures if the value
|
||||
# changes, we'll miss the cache, thus sending the field update
|
||||
# to the syncing user.
|
||||
import json
|
||||
|
||||
cache_value = hashlib.sha256(
|
||||
f"{other_user_id}-{field_name}-{profile_data.get(field_name)}".encode(
|
||||
"utf8"
|
||||
)
|
||||
json.dumps(
|
||||
[other_user_id, field_name, profile_data.get(field_name)],
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
).encode("utf8")
|
||||
).hexdigest()
|
||||
if cache.get(cache_value) is None:
|
||||
per_user_updates[field_name] = profile_data.get(field_name)
|
||||
|
||||
@@ -884,10 +884,12 @@ class ProfileWorkerStore(SQLBaseStore):
|
||||
values=values,
|
||||
)
|
||||
|
||||
# Add per user tracking rows pointing to the latest stream ID
|
||||
# Add per user tracking rows for each generated stream ID
|
||||
inserted_ts = self.clock.time_msec()
|
||||
per_user_values = [
|
||||
(stream_ids[-1], user_id, inserted_ts) for user_id in target_users
|
||||
(stream_id, user_id, inserted_ts)
|
||||
for user_id in target_users
|
||||
for stream_id in stream_ids
|
||||
]
|
||||
self.db_pool.simple_insert_many_txn(
|
||||
txn,
|
||||
@@ -1049,25 +1051,20 @@ class ProfileWorkerStore(SQLBaseStore):
|
||||
)
|
||||
res = txn.fetchall()
|
||||
if res:
|
||||
stream_ids = [row[0] for row in res]
|
||||
|
||||
user_clause, user_args = make_in_list_sql_clause(
|
||||
txn.database_engine,
|
||||
"user_id",
|
||||
users_to_update,
|
||||
)
|
||||
stream_id_clause, stream_id_args = make_in_list_sql_clause(
|
||||
txn.database_engine,
|
||||
"stream_id",
|
||||
stream_ids,
|
||||
)
|
||||
txn.execute(
|
||||
f"""
|
||||
DELETE FROM profile_updates_per_user
|
||||
WHERE {user_clause}
|
||||
AND {stream_id_clause}
|
||||
AND stream_id IN (
|
||||
SELECT stream_id FROM profile_updates WHERE user_id = ?
|
||||
)
|
||||
""",
|
||||
(*user_args, *stream_id_args),
|
||||
(*user_args, user_id.to_string()),
|
||||
)
|
||||
|
||||
# Now record the "left room" action in the stream
|
||||
|
||||
Reference in New Issue
Block a user