DEV: Reduce number of jobs enqueued.

DEV: Reduce number of jobs enqueued.

Apply code review suggestion from 405ba00c08a86778a7baf28e93388201162a5347.

diff --git a/app/jobs/regular/notify_post_revision.rb b/app/jobs/regular/notify_post_revision.rb
index d7e38a8..b0b0794 100644
--- a/app/jobs/regular/notify_post_revision.rb
+++ b/app/jobs/regular/notify_post_revision.rb
@@ -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
diff --git a/app/services/post_action_notifier.rb b/app/services/post_action_notifier.rb
index 9d8bb92..3e3fd46 100644
--- a/app/services/post_action_notifier.rb
+++ b/app/services/post_action_notifier.rb
@@ -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|
-
-        Jobs.enqueue(:notify_post_revision,
-          user_id: topic_user.user_id,
-          post_revision_id: post_revision.id
-        )
-      end
+      user_ids.concat(
+        TopicUser.watching(post.topic_id)
+          .where.not(user_id: post_revision.user_id)
+          .where(topic: post.topic)
+          .pluck(:user_id)
+      )
+    end
+
+    if user_ids.present?
+      Jobs.enqueue(:notify_post_revision,
+        user_ids: user_ids,
+        post_revision_id: post_revision.id
+      )
     end
   end
 
diff --git a/notify_post_revision.rb b/notify_post_revision.rb
deleted file mode 100644
index d94d193..0000000
--- a/notify_post_revision.rb
+++ /dev/null
@@ -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

GitHub sha: f04518fd