mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 17:24:42 +08:00
DEV: Reduce number of jobs enqueued.
Apply code review suggestion from
405ba00c08
.
This commit is contained in:
parent
ba6904bb27
commit
f04518fdf9
|
@ -1,20 +1,23 @@
|
|||
module Jobs
|
||||
class NotifyPostRevision < Jobs::Base
|
||||
def execute(args)
|
||||
user = User.find_by(id: args[:user_id])
|
||||
raise Discourse::InvalidParameters.new(:user_id) unless user
|
||||
raise Discourse::InvalidParameters.new(:user_ids) unless args[:user_ids]
|
||||
|
||||
post_revision = PostRevision.find_by(id: args[:post_revision_id])
|
||||
raise Discourse::InvalidParameters.new(:post_revision_id) unless post_revision
|
||||
|
||||
PostActionNotifier.alerter.create_notification(
|
||||
user,
|
||||
Notification.types[:edited],
|
||||
post_revision.post,
|
||||
display_username: post_revision.user.username,
|
||||
acting_user_id: post_revision.try(:user_id),
|
||||
revision_number: post_revision.number
|
||||
)
|
||||
ActiveRecord::Base.transaction do
|
||||
User.where(id: args[:user_ids]).find_each do |user|
|
||||
PostActionNotifier.alerter.create_notification(
|
||||
user,
|
||||
Notification.types[:edited],
|
||||
post_revision.post,
|
||||
display_username: post_revision.user.username,
|
||||
acting_user_id: post_revision&.user_id,
|
||||
revision_number: post_revision.number
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,24 +97,26 @@ class PostActionNotifier
|
|||
return if post.topic.private_message?
|
||||
return if SiteSetting.disable_edit_notifications && post_revision.user_id == Discourse::SYSTEM_USER_ID
|
||||
|
||||
user_ids = []
|
||||
|
||||
if post_revision.user_id != post.user_id
|
||||
Jobs.enqueue(:notify_post_revision,
|
||||
user_id: post.user_id,
|
||||
post_revision_id: post_revision.id
|
||||
)
|
||||
user_ids << post.user_id
|
||||
end
|
||||
|
||||
if post.wiki && post.is_first_post?
|
||||
TopicUser.watching(post.topic_id)
|
||||
.where.not(user_id: post_revision.user_id)
|
||||
.where(topic: post.topic)
|
||||
.find_each do |topic_user|
|
||||
user_ids.concat(
|
||||
TopicUser.watching(post.topic_id)
|
||||
.where.not(user_id: post_revision.user_id)
|
||||
.where(topic: post.topic)
|
||||
.pluck(:user_id)
|
||||
)
|
||||
end
|
||||
|
||||
Jobs.enqueue(:notify_post_revision,
|
||||
user_id: topic_user.user_id,
|
||||
post_revision_id: post_revision.id
|
||||
)
|
||||
end
|
||||
if user_ids.present?
|
||||
Jobs.enqueue(:notify_post_revision,
|
||||
user_ids: user_ids,
|
||||
post_revision_id: post_revision.id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
module Jobs
|
||||
class NotifyPostRevision < Jobs::Base
|
||||
def execute(args)
|
||||
user = User.find_by(id: args[:user_id])
|
||||
raise Discourse::InvalidParameters.new(:user_id) unless user
|
||||
|
||||
post_revision = PostRevision.find_by(id: args[:post_revision_id])
|
||||
raise Discourse::InvalidParameters.new(:post_revision_id) unless post_revision
|
||||
|
||||
PostActionNotifier.alerter.create_notification(
|
||||
user,
|
||||
Notification.types[:edited],
|
||||
post_revision.post,
|
||||
display_username: post_revision.user.username,
|
||||
acting_user_id: post_revision&.user_id,
|
||||
revision_number: post_revision.number
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user