DEV: TopicTrackingState calls should happen in the background (#11682)
* DEV: TopicTrackingState calls should happen in the background It was observed that calling TopicTrackingState on popular topics could result in a large number of calls to redis, resulting in slow response times when posting replies. These calls should be moved to a background job. * DEV: PostUpdateTopicTrackingState should execute on default queue
This commit is contained in:
parent
3eae4d3669
commit
b1f32f2f57
|
@ -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
|
||||||
|
end
|
|
@ -57,12 +57,7 @@ class PostJobsEnqueuer
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_post_create
|
def after_post_create
|
||||||
TopicTrackingState.publish_unmuted(@post.topic)
|
Jobs.enqueue(:post_update_topic_tracking_state, post_id: @post.id)
|
||||||
if @post.post_number > 1
|
|
||||||
TopicTrackingState.publish_muted(@post.topic)
|
|
||||||
TopicTrackingState.publish_unread(@post)
|
|
||||||
end
|
|
||||||
TopicTrackingState.publish_latest(@topic, @post.whisper?)
|
|
||||||
|
|
||||||
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
||||||
:notify_mailing_list_subscribers,
|
:notify_mailing_list_subscribers,
|
||||||
|
|
|
@ -128,8 +128,13 @@ describe PostCreator do
|
||||||
expect(channels.find { |s| s =~ /new/ }).to eq(nil)
|
expect(channels.find { |s| s =~ /new/ }).to eq(nil)
|
||||||
end
|
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.enable
|
UserActionManager.enable
|
||||||
|
|
||||||
admin = Fabricate(:admin)
|
admin = Fabricate(:admin)
|
||||||
|
@ -169,7 +174,7 @@ describe PostCreator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'generates the correct messages for a normal topic' do
|
it 'generates the correct messages for a normal topic' do
|
||||||
|
Jobs.run_immediately!
|
||||||
UserActionManager.enable
|
UserActionManager.enable
|
||||||
|
|
||||||
p = nil
|
p = nil
|
||||||
|
|
Loading…
Reference in New Issue