Class: Workarea::BulkIndexProducts

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/bulk_index_products.rb

Class Method Summary collapse

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(100) do |group|
    perform_by_models(Catalog::Product.in(id: group).to_a)
  end
end

.perform_by_models(products) ⇒ Object



14
15
16
17
18
19
20
21
# File 'app/workers/workarea/bulk_index_products.rb', line 14

def perform_by_models(products)
  return if products.blank?

  documents = Search::ProductEntries.new(products).map(&:as_bulk_document)

  Search::Storefront.bulk(documents)
  products.each { |p| p.set(last_indexed_at: Time.current) }
end

Instance Method Details

#perform(ids) ⇒ Object



24
25
26
# File 'app/workers/workarea/bulk_index_products.rb', line 24

def perform(ids)
  self.class.perform(ids)
end