Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18345.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix minor performance regression caused by tracking of room participation. Regressed in v1.128.0.
20 changes: 8 additions & 12 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -1622,14 +1622,11 @@ def _set_room_participation_txn(
sql = """
UPDATE room_memberships
SET participant = true
WHERE (user_id, room_id) IN (
SELECT user_id, room_id
FROM room_memberships
WHERE user_id = ?
AND room_id = ?
ORDER BY event_stream_ordering DESC
LIMIT 1
WHERE event_id IN (
SELECT event_id FROM local_current_membership

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that right? local_current_membership seems to only have memberships for our users whereas room_memberships also has remote users?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is only for local users though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erik Sorry for the hassle here - the intention with this statement and the one below was to get/set the participant value just for the user's most recent entry in room_memberships. The original desire was to track both local and non-local participation, but thinking through it a bit I don't think it's a huge problem to limit it to local users (and since this is only called in messages it's not tracking federation participation currently anyway), especially if that will reduce resource consumption.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. As far as I can tell we only call set_room_participation from EventCreationHandler, which only deals with local users.

The query is easy to convert to also working with remote users by swapping local_current_membership to current_state_events table.

WHERE user_id = ? AND room_id = ?
)
AND NOT participant
"""
txn.execute(sql, (user_id, room_id))

Expand All @@ -1651,11 +1648,10 @@ def _get_room_participation_txn(
) -> bool:
sql = """
SELECT participant
FROM room_memberships
WHERE user_id = ?
AND room_id = ?
ORDER BY event_stream_ordering DESC
LIMIT 1
FROM local_current_membership AS l
INNER JOIN room_memberships AS r USING (event_id)
WHERE l.user_id = ?
AND l.room_id = ?
"""
txn.execute(sql, (user_id, room_id))
res = txn.fetchone()
Expand Down