FIX: IndexCategoryForSearch category_id job exception (#11239)

On category create an exception will be thrown on this job because the
save transaction hasn't completed yet and the job cannot find the
category id. To prevent this we can use the rails 6 `after_save_commit`
hook that will fire after the category save transaction has finished for
both update and create actions.
This commit is contained in:
Blake Erickson 2020-11-16 10:18:25 -07:00 committed by GitHub
parent 689623ffc0
commit 06084fb8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -77,7 +77,6 @@ class Category < ActiveRecord::Base
after_save :reset_topic_ids_cache
after_save :clear_subcategory_ids
after_save :clear_url_cache
after_save :index_search
after_save :update_reviewables
after_destroy :reset_topic_ids_cache
@ -93,6 +92,8 @@ class Category < ActiveRecord::Base
after_commit :trigger_category_updated_event, on: :update
after_commit :trigger_category_destroyed_event, on: :destroy
after_save_commit :index_search
belongs_to :parent_category, class_name: 'Category'
has_many :subcategories, class_name: 'Category', foreign_key: 'parent_category_id'