Sha256: 52cc42671a3fba5f97aa5629f7607cdba3c299ec019a33b6e45ce47d41d0033c

Contents?: true

Size: 785 Bytes

Versions: 10

Compression:

Stored size: 785 Bytes

Contents

module Workarea
  class BulkIndexSearches
    include Sidekiq::Worker

    class << self
      def perform(ids = popular_searches.pluck(:id))
        ids.each_slice(Workarea.config.bulk_index_batch_size) do |group|
          perform_by_models(Metrics::SearchByWeek.in(id: group).to_a)
        end
      end

      def popular_searches
        Metrics::SearchByWeek
          .last_week
          .has_results
          .most_searched
          .limit(Workarea.config.max_searches_to_index)
      end

      def perform_by_models(searches)
        documents = searches.map do |model|
          Search::Storefront::Search.new(model).as_bulk_document
        end

        Search::Storefront.bulk(documents)
      end
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
workarea-core-3.5.8 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.7 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.6 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.5 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.4 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.3 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.2 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.1 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.0 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.0.beta.1 app/workers/workarea/bulk_index_searches.rb