mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 10:53:44 +08:00
10ddb8a9c4
Rails has an odd behavior for calling .delete_all on a has_many relation - the default behavior is to nullify the foreign key fields instead of actually 'DELETE'ing the records. Additionally, publishing a shared draft topic creates a PostRevision that the NotifyPostRevision job picks up which is then promptly deleted. Use destroy_all when cleaning up the revisions and have the NotifyPostRevision job tolerate deleted PostRevision records. This takes a small performance hit (several SQL DELETEs instead of just one) but shouldn't be too much of an issue (high cardinalities range from 30-100).
28 lines
813 B
Ruby
28 lines
813 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class NotifyPostRevision < ::Jobs::Base
|
|
def execute(args)
|
|
raise Discourse::InvalidParameters.new(:user_ids) unless args[:user_ids]
|
|
|
|
post_revision = PostRevision.find_by(id: args[:post_revision_id])
|
|
return if post_revision.nil?
|
|
|
|
ActiveRecord::Base.transaction do
|
|
User.where(id: args[:user_ids]).find_each do |user|
|
|
next if post_revision.hidden && !user.staff?
|
|
|
|
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
|