discourse/plugins/chat/app/jobs/regular/send_message_notifications.rb
Roman Rizzi 2f61d26e3d
PERF: Make chat mention notifications async. (#19666)
This PR removes the limit added to max_users_notified_per_group_mention during #19034 and improve the performance when expanding mentions for large channel or groups by removing some N+1 queries and making the whole process async.

* Fully async chat message notifications

* Remove mention setting limit and get rid of N+1 queries
2023-01-02 11:54:52 -03:00

22 lines
573 B
Ruby

# frozen_string_literal: true
module Jobs
class SendMessageNotifications < ::Jobs::Base
def execute(args)
reason = args[:reason]
valid_reasons = %w[new edit]
return unless valid_reasons.include?(reason)
return if (timestamp = args[:timestamp]).blank?
return if (message = ChatMessage.find_by(id: args[:chat_message_id])).nil?
if reason == "new"
Chat::ChatNotifier.new(message, timestamp).notify_new
elsif reason == "edit"
Chat::ChatNotifier.new(message, timestamp).notify_edit
end
end
end
end