Fix query for room participation#18345
Conversation
Follow on from #18068
| ORDER BY event_stream_ordering DESC | ||
| LIMIT 1 | ||
| WHERE event_id IN ( | ||
| SELECT event_id FROM local_current_membership |
There was a problem hiding this comment.
is that right? local_current_membership seems to only have memberships for our users whereas room_memberships also has remote users?
There was a problem hiding this comment.
Yeah, this is only for local users though
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
Follow on from #18068
Currently the subquery in
UPDATEis pointless, as it will still just update allroom_membershiprows. Instead, we should look at the current membership event ID (which is easily retrieved fromlocal_current_membership). We also add aAND NOT participantto noop theUPDATEwhen theparticipantflag is already set.cc @H-Shay