Class: Workarea::BulkIndexProducts
- Inherits:
-
Object
- Object
- Workarea::BulkIndexProducts
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/workarea/bulk_index_products.rb
Class Method Summary collapse
- .perform(ids = Catalog::Product.pluck(:id)) ⇒ Object
- .perform_by_models(products) ⇒ Object (also: perform_by_model)
Instance Method Summary collapse
Class Method Details
.perform(ids = Catalog::Product.pluck(:id)) ⇒ Object
8 9 10 11 12 |
# File 'app/workers/workarea/bulk_index_products.rb', line 8 def perform(ids = Catalog::Product.pluck(:id)) ids.each_slice(Workarea.config.bulk_index_batch_size) do |group| perform_by_models(Catalog::Product.in(id: group).to_a) end end |
.perform_by_models(products) ⇒ Object Also known as: perform_by_model
14 15 16 17 18 19 20 21 22 |
# File 'app/workers/workarea/bulk_index_products.rb', line 14 def perform_by_models(products) return if products.blank? products = Array.wrap(products) documents = Search::ProductEntries.new(products).map(&:as_bulk_document) Search::Storefront.bulk(documents) Catalog::Product.in(id: products.map(&:id)).set(last_indexed_at: Time.current) end |
Instance Method Details
#perform(ids) ⇒ Object
26 27 28 |
# File 'app/workers/workarea/bulk_index_products.rb', line 26 def perform(ids) self.class.perform(ids) end |