mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
PERF: Move post alerting into async
This commit is contained in:
parent
6ae58d41a7
commit
5990ab855b
5 changed files with 22 additions and 2 deletions
11
app/jobs/regular/post_alert.rb
Normal file
11
app/jobs/regular/post_alert.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Jobs
|
||||
class PostAlert < Jobs::Base
|
||||
|
||||
def execute(args)
|
||||
post = Post.find(args[:post_id])
|
||||
PostAlerter.post_created(post)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -190,6 +190,7 @@ class PostAlerter
|
|||
|
||||
exclude_user_ids << reply_to_user.id if reply_to_user.present?
|
||||
exclude_user_ids.flatten!
|
||||
|
||||
TopicUser
|
||||
.where(topic_id: post.topic_id, notification_level: TopicUser.notification_levels[:watching])
|
||||
.includes(:user).each do |tu|
|
||||
|
|
|
@ -129,7 +129,6 @@ class PostCreator
|
|||
|
||||
if @post && errors.blank?
|
||||
publish
|
||||
PostAlerter.post_created(@post) unless @opts[:import_mode]
|
||||
|
||||
track_latest_on_category
|
||||
enqueue_jobs
|
||||
|
|
|
@ -9,17 +9,22 @@ class PostJobsEnqueuer
|
|||
def enqueue_jobs
|
||||
# We need to enqueue jobs after the transaction. Otherwise they might begin before the data has
|
||||
# been comitted.
|
||||
enqueue_post_alerts unless @opts[:import_mode]
|
||||
feature_topic_users unless @opts[:import_mode]
|
||||
trigger_post_post_process
|
||||
|
||||
unless skip_after_create?
|
||||
after_post_create
|
||||
after_topic_create
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def enqueue_post_alerts
|
||||
Jobs.enqueue(:post_alert, post_id: @post.id)
|
||||
end
|
||||
|
||||
def feature_topic_users
|
||||
Jobs.enqueue(:feature_topic_users, topic_id: @topic.id)
|
||||
end
|
||||
|
|
|
@ -137,6 +137,7 @@ describe PostCreator do
|
|||
it 'queues up post processing job when saved' do
|
||||
Jobs.expects(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:post_alert, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:notify_mailing_list_subscribers, has_key(:post_id))
|
||||
creator.create
|
||||
end
|
||||
|
@ -144,6 +145,7 @@ describe PostCreator do
|
|||
it 'passes the invalidate_oneboxes along to the job if present' do
|
||||
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
Jobs.expects(:enqueue).with(:notify_mailing_list_subscribers, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:post_alert, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:invalidate_oneboxes))
|
||||
creator.opts[:invalidate_oneboxes] = true
|
||||
creator.create
|
||||
|
@ -152,6 +154,7 @@ describe PostCreator do
|
|||
it 'passes the image_sizes along to the job if present' do
|
||||
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
Jobs.expects(:enqueue).with(:notify_mailing_list_subscribers, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:post_alert, has_key(:post_id))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:image_sizes))
|
||||
creator.opts[:image_sizes] = {'http://an.image.host/image.jpg' => {'width' => 17, 'height' => 31}}
|
||||
creator.create
|
||||
|
@ -491,6 +494,7 @@ describe PostCreator do
|
|||
# does not notify an unrelated user
|
||||
expect(unrelated.notifications.count).to eq(0)
|
||||
expect(post.topic.subtype).to eq(TopicSubtype.user_to_user)
|
||||
|
||||
expect(target_user1.notifications.count).to eq(1)
|
||||
expect(target_user2.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue