mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 02:43:39 +08:00
71391cd40d
When chat is enabled, there's a scheduled job that runs every 5 minutes to check whether we need to send a "chat summary" email to users with unread chat messages or mentions. On Discourse with a large number of users, the query used wasn't optimal and sometimes taking minutes. Which isn't good when the query is called every 5 minutes 😬 This PR reworks the query in `Chat::Mailer.send_unread_mentions_summary`. Instead of starting from the `users` table, it starts from the `user_chat_channel_memberships` table which is the main piece tying everything together. The new query is mostly similar to the previous one, with some bug fixes (like ensuring the user has `allow_private_messages` enabled for direct messages) and is also slightly simpler since it doesn't keep track of the `memberships_with_unread_messages` anymore. That part has been moved to the `user_notifications.chat_summary` email method. The `UserEmailExtension` has been deleted since that was using to N+1 update the `user_chat_channel_memberships.last_unread_mention_when_emailed_it`(quite a mouthful 😛) but that's now done directly in the `user_notifications.chat_summary` email method. The "plat de résistance" of that PR - the `user_notifications.chat_summary` method has been re-worked for improved performances 🚀 Instead of doing everything in one query, it does 4 tiny ones. - One to retrieve the list of unread mentions (@something) in "category" channels - One to retrieve the list of unread messages in "direct message" channels (aka. 1-1 and group discussions) - One to load all the chat messages for each "category" channels from the last unread mention - One to load all the chat messages for each "direct message" channels from the last unread message All the specs for both `Chat::Mailer` and `UserNotification.chat_summary` have been rewriten for easier comprehension and faster execution (mostly by not using chat services which makes the specs go 10x slower...) Internal ref - t/129848 |
||
---|---|---|
.. | ||
bookmark_extension.rb | ||
category_extension.rb | ||
channel_archive_service.rb | ||
channel_fetcher.rb | ||
channel_hashtag_data_source.rb | ||
channel_membership_manager.rb | ||
duplicate_message_validator.rb | ||
engine.rb | ||
group_extension.rb | ||
guardian_extensions.rb | ||
mailer.rb | ||
message_bookmarkable.rb | ||
message_mover.rb | ||
message_processor.rb | ||
message_rate_limiter.rb | ||
message_reactor.rb | ||
messages_exporter.rb | ||
notification_levels.rb | ||
notifier.rb | ||
onebox_handler.rb | ||
outgoing_web_hook_extension.rb | ||
parsed_mentions.rb | ||
plugin_instance_extension.rb | ||
post_notification_handler.rb | ||
review_queue.rb | ||
reviewable_extension.rb | ||
secure_uploads_compatibility.rb | ||
seeder.rb | ||
slack_compatibility.rb | ||
statistics.rb | ||
transcript_service.rb | ||
user_extension.rb | ||
user_notifications_extension.rb | ||
user_option_extension.rb |