A platform for community discussion. Free, open, simple.
DEV: TopicTrackingState calls should happen in the background (#11682)
jbrwb1f32f2f5717
diff --git a/app/jobs/regular/post_update_topic_tracking_state.rb b/app/jobs/regular/post_update_topic_tracking_state.rbnew file mode 100644index 00000000000..c68a67b8a28--- /dev/null+++ b/app/jobs/regular/post_update_topic_tracking_state.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++module Jobs+ class PostUpdateTopicTrackingState < ::Jobs::Base++ def execute(args)+ post = Post.find_by(id: args[:post_id])++ if post+ TopicTrackingState.publish_unmuted(post.topic)+ if post.post_number > 1+ TopicTrackingState.publish_muted(post.topic)+ TopicTrackingState.publish_unread(post)+ end+ TopicTrackingState.publish_latest(post.topic, post.whisper?)+ end+ end++ end+enddiff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rbindex cd80eaa61ca..1fbbe0183af 100644--- a/lib/post_jobs_enqueuer.rb+++ b/lib/post_jobs_enqueuer.rb@@ -57,12 +57,7 @@ class PostJobsEnqueuerenddef after_post_create- TopicTrackingState.publish_unmuted(@post.topic)- if @post.post_number > 1- TopicTrackingState.publish_muted(@post.topic)- TopicTrackingState.publish_unread(@post)- end- TopicTrackingState.publish_latest(@topic, @post.whisper?)+ Jobs.enqueue(:post_update_topic_tracking_state, post_id: @post.id)Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,:notify_mailing_list_subscribers,diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex 310ba1aea7e..536015bcc1e 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -128,8 +128,13 @@ describe PostCreator doexpect(channels.find { |s| s =~ /new/ }).to eq(nil)end- it "generates the correct messages for a secure topic" do+ it 'enqueues job to generate messages' do+ p = creator.create+ expect(job_enqueued?(job: :post_update_topic_tracking_state, args: { post_id: p.id })).to eq(true)+ end+ it "generates the correct messages for a secure topic" do+ Jobs.run_immediately!UserActionManager.enableadmin = Fabricate(:admin)@@ -169,7 +174,7 @@ describe PostCreator doendit 'generates the correct messages for a normal topic' do-+ Jobs.run_immediately!UserActionManager.enablep = nil