PERF: Defer indexing post for search when saving a post.
Indexing a post for search is slow and there is no reason for us to have to block saving a post due to search indexing.
This commit is contained in:
parent
f4a0d200ee
commit
337f062f0f
|
@ -57,7 +57,7 @@ class Post < ActiveRecord::Base
|
|||
|
||||
validates_with PostValidator, unless: :skip_validation
|
||||
|
||||
after_save :index_search
|
||||
after_commit :index_search
|
||||
|
||||
# We can pass several creating options to a post via attributes
|
||||
attr_accessor :image_sizes, :quoted_post_numbers, :no_bump, :invalidate_oneboxes, :cooking_options, :skip_unique_check, :skip_validation
|
||||
|
@ -898,7 +898,9 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def index_search
|
||||
SearchIndexer.index(self)
|
||||
Scheduler::Defer.later "Index post for search" do
|
||||
SearchIndexer.index(self)
|
||||
end
|
||||
end
|
||||
|
||||
def locked?
|
||||
|
|
|
@ -201,9 +201,9 @@ class SearchIndexer
|
|||
|
||||
if Post === obj && obj.raw.present? &&
|
||||
(
|
||||
force ||
|
||||
obj.saved_change_to_cooked? ||
|
||||
obj.saved_change_to_topic_id? ||
|
||||
force
|
||||
obj.saved_change_to_topic_id?
|
||||
)
|
||||
|
||||
if topic
|
||||
|
|
Loading…
Reference in New Issue