PERF: Update index for category in a background job.

Search indexing can get expensive and there is no need for us to block
the entire request just to wait for index to finish.
This commit is contained in:
Guo Xiang Tan
2020-11-09 13:35:37 +08:00
committed by Alan Guo Xiang Tan
parent 94cd5ac0b1
commit 650da7b626
4 changed files with 16 additions and 5 deletions

View File

@@ -778,11 +778,10 @@ class Category < ActiveRecord::Base
end
def index_search
if saved_change_to_attribute?(:name)
SearchIndexer.queue_category_posts_reindex(self.id)
end
SearchIndexer.index(self)
Jobs.enqueue(:index_category_for_search,
category_id: self.id,
force: saved_change_to_attribute?(:name),
)
end
def update_reviewables