FIX: Missing post/topic created web hooks due to race condition.
This commit is contained in:
parent
9644569a28
commit
ad02437358
|
@ -62,7 +62,12 @@ class QueuedPost < ActiveRecord::Base
|
|||
def approve!(approved_by)
|
||||
created_post = nil
|
||||
|
||||
creator = PostCreator.new(user, create_options.merge(skip_validations: true, skip_jobs: true))
|
||||
creator = PostCreator.new(user, create_options.merge(
|
||||
skip_validations: true,
|
||||
skip_jobs: true,
|
||||
skip_events: true
|
||||
))
|
||||
|
||||
QueuedPost.transaction do
|
||||
change_to!(:approved, approved_by)
|
||||
|
||||
|
@ -77,6 +82,7 @@ class QueuedPost < ActiveRecord::Base
|
|||
|
||||
# Do sidekiq work outside of the transaction
|
||||
creator.enqueue_jobs
|
||||
creator.trigger_after_events
|
||||
|
||||
DiscourseEvent.trigger(:approved_post, self, created_post)
|
||||
created_post
|
||||
|
|
|
@ -188,7 +188,7 @@ class PostCreator
|
|||
enqueue_jobs unless @opts[:skip_jobs]
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
||||
|
||||
trigger_after_events(@post)
|
||||
trigger_after_events unless opts[:skip_events]
|
||||
|
||||
auto_close unless @opts[:import_mode]
|
||||
end
|
||||
|
@ -219,6 +219,11 @@ class PostCreator
|
|||
).enqueue_jobs
|
||||
end
|
||||
|
||||
def trigger_after_events
|
||||
DiscourseEvent.trigger(:topic_created, @post.topic, @opts, @user) unless @opts[:topic_id]
|
||||
DiscourseEvent.trigger(:post_created, @post, @opts, @user)
|
||||
end
|
||||
|
||||
def self.track_post_stats
|
||||
Rails.env != "test".freeze || @track_post_stats
|
||||
end
|
||||
|
@ -284,11 +289,6 @@ class PostCreator
|
|||
end
|
||||
end
|
||||
|
||||
def trigger_after_events(post)
|
||||
DiscourseEvent.trigger(:topic_created, post.topic, @opts, @user) unless @opts[:topic_id]
|
||||
DiscourseEvent.trigger(:post_created, post, @opts, @user)
|
||||
end
|
||||
|
||||
def auto_close
|
||||
if @post.topic.private_message? &&
|
||||
!@post.topic.closed &&
|
||||
|
|
Loading…
Reference in New Issue