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
36 37 38 |
# File 'app/workers/workarea/index_category_changes.rb', line 36 def max_count Workarea.config.category_inline_index_product_max_count end |
#perform(changes) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/workers/workarea/index_category_changes.rb', line 12 def perform(changes) return unless changes['product_ids'].present? ids = require_index_ids(*changes['product_ids']) if ids.size > max_count ids.each_slice(max_count) do |ids| BulkIndexProducts.perform_async(ids) end else BulkIndexProducts.perform(ids) end end |
#require_index_ids(previous_ids, new_ids) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/workers/workarea/index_category_changes.rb', line 26 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 |