Sha256: e299f00361e17dae986359c31c637aeab7c2a3881f649acb2284c8a5d715f912

Contents?: true

Size: 811 Bytes

Versions: 18

Compression:

Stored size: 811 Bytes

Contents

module Workarea
  class BulkIndexProducts
    include Sidekiq::Worker

    sidekiq_options lock: :until_executing

    class << self
      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

      def perform_by_models(products)
        return if products.blank?
        products = Array.wrap(products)

        Search::Storefront.bulk do
          Search::ProductEntries.new(products).map(&:as_bulk_document)
        end

        Catalog::Product.in(id: products.map(&:id)).set(last_indexed_at: Time.current)
      end
      alias_method :perform_by_model, :perform_by_models
    end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.26 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.25 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.23 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.22 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.21 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.20 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.19 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.18 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.17 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.16 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.15 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.14 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.13 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.12 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.11 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.10 app/workers/workarea/bulk_index_products.rb
workarea-core-3.5.9 app/workers/workarea/bulk_index_products.rb