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

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Jun 7, 2023

Remove extra current_state_events join from queries to grab profile info

Spawning from #15731

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

@MadLittleMods MadLittleMods added the A-Database DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db label Jun 7, 2023
Comment on lines -227 to -232
SELECT state_key, display_name, avatar_url FROM room_memberships as m
INNER JOIN current_state_events as c
ON m.event_id = c.event_id
AND m.room_id = c.room_id
AND m.user_id = c.state_key
WHERE c.type = 'm.room.member' AND c.room_id = ? AND m.membership = ? AND %s
Copy link
Contributor Author

@MadLittleMods MadLittleMods Jun 7, 2023

Choose a reason for hiding this comment

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

I think this is equivalent to the old thing. Please double-check.

I assume room_memberships holds current memberships just as much current_state_events would.

room_memberships is an append-only table which means it holds all membership forever but we only look at Membership.JOIN here which should represent current state since they would be LEAVE or some other membership otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with this is that there are multiple entries for a given user_id and we don't know which is the latest just from the room_memberships table alone

Example:

SELECT user_id, display_name, avatar_url FROM room_memberships
WHERE room_id = '!abc:matrix.org' AND membership = 'join';
           user_id            |         display_name          |                avatar_url
------------------------------+-------------------------------+-------------------------------------------
 @madlittlemods:matrix.org    | madlittlemods                 |
 @madlittlemods:matrix.org    | madlittlemods                 | mxc://matrix.org/bDayqThxTIcGNcskzIADknRv
 @madlittlemods:matrix.org    | madlittlemods (Eric Eastwood) | mxc://matrix.org/bDayqThxTIcGNcskzIADknRv

@MadLittleMods MadLittleMods added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Jun 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Database DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant