Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Redesign chat mentions #24752

Merged
merged 16 commits into from
Jan 17, 2024
Merged

Conversation

AndrewPrigorshnev
Copy link
Contributor

@AndrewPrigorshnev AndrewPrigorshnev commented Dec 6, 2023

At the moment, when someone is mentioning a group, or using here or all mention, we create a chat_mention record per user. What we want instead is to have special kinds of mentions, so we can create only one chat_mention record in such cases. This PR implements that.

Note, that such mentions will still have N related notifications, one notification per a user. We don't expect we'll have performance problems on the notifications side, but if at some point we do, we should be able to solve them on the side of notifications (notifications are handled in jobs, also some little delays with the notifications are acceptable, so we can make sure notifications are properly queued, and that processing of every notification is fast enough to make delays small enough).

The preparation work for this PR was done in fbd24fa, where we make it possible for one mention to have several related notifications.

A pretty tricky part of this PR is schema and data migration, I've explained related details inline on the migration files.

@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Dec 6, 2023
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 7 times, most recently from b2cb27f to 2887a5e Compare December 8, 2023 12:11
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 4 times, most recently from 7c338d0 to 1c8f343 Compare December 19, 2023 20:06
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 2 times, most recently from ad23354 to d9ba3a7 Compare December 22, 2023 18:28
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 15 times, most recently from e839fb4 to 542a1b0 Compare December 28, 2023 16:11
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 2 times, most recently from fa0534e to a06deea Compare January 4, 2024 16:22
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 2 times, most recently from cc139ae to aef0bfd Compare January 15, 2024 19:06
@AndrewPrigorshnev
Copy link
Contributor Author

@jjaffeux, I've rebased the branch and also fixed test failures (the most of them were because of a typo). I've also addressed your recent comment regarding change_column_null.

Copy link
Contributor

@jjaffeux jjaffeux left a comment

Choose a reason for hiding this comment

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

Ok, didn't retry it locally this time, but it seems fine and not much has changed anyways. 🚀

@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch 2 times, most recently from fccece3 to c687487 Compare January 16, 2024 15:57
@AndrewPrigorshnev AndrewPrigorshnev force-pushed the dev/rethink-mass-mentions-polymorphic branch from c687487 to 87e8de1 Compare January 17, 2024 10:23
@AndrewPrigorshnev AndrewPrigorshnev merged commit 62f423d into main Jan 17, 2024
19 checks passed
@AndrewPrigorshnev AndrewPrigorshnev deleted the dev/rethink-mass-mentions-polymorphic branch January 17, 2024 11:24
target_id = user_id
elsif mention_klass == ::Chat::GroupMention
begin
target_id = Group.where("LOWER(name) = ?", "#{mention_type}").first.id
Copy link
Member

@ZogStriP ZogStriP Jan 17, 2024

Choose a reason for hiding this comment

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

Nitpick: if you only care about some fields about 1 record, you can use #pick and list the fields you want.

This avoids loading the whole record in memory (due to the .first) when we only want the id.

Suggested change
target_id = Group.where("LOWER(name) = ?", "#{mention_type}").first.id
target_id = Group.where("LOWER(name) = ?", "#{mention_type}").pick(:id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, merged the PR before I saw this. I've fixed it in a follow-up – #25301.

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/query-causing-400-cpu-load/285542/27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat PRs which include a change to Chat plugin
4 participants