Class: Workarea::IndexCategoryChanges
- Inherits:
-
Object
- Object
- Workarea::IndexCategoryChanges
- Includes:
- Sidekiq::CallbacksWorker, Sidekiq::Worker
- Defined in:
- app/workers/workarea/index_category_changes.rb
Instance Method Summary collapse
Instance Method Details
#max_count ⇒ Object
41 42 43 |
# File 'app/workers/workarea/index_category_changes.rb', line 41 def max_count Workarea.config.category_inline_index_product_max_count end |
#perform(changes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/workers/workarea/index_category_changes.rb', line 13 def perform(changes) return unless changes['product_ids'].present? ids = require_index_ids(*changes['product_ids']) if ids.size > max_count ids.each { |id| IndexProduct.perform_async(id) } else Catalog::Product.in(id: ids).each do |product| begin IndexProduct.perform(product) rescue IndexProduct.perform_async(product.id) end end end end |
#require_index_ids(previous_ids, new_ids) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/workers/workarea/index_category_changes.rb', line 31 def require_index_ids(previous_ids, new_ids) previous_ids = Array.wrap(previous_ids) new_ids = Array.wrap(new_ids) new_ids.reject do |id| previous_ids.index(id).present? && previous_ids.index(id) == new_ids.index(id) end + (previous_ids - new_ids) end |