Sha256: 63d73c5f1d4ebba8d0f405259d1f673b09baa0cab8f7d4011a8cfb46d579d960

Contents?: true

Size: 751 Bytes

Versions: 19

Compression:

Stored size: 751 Bytes

Contents

module Workarea
  class BulkIndexSearches
    include Sidekiq::Worker

    class << self
      def perform(ids = popular_searches.pluck(:id))
        ids.each_slice(100) 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

19 entries across 19 versions & 1 rubygems

Version Path
workarea-core-3.4.30 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.29 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.28 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.27 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.26 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.25 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.24 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.23 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.22 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.21 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.20 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.19 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.18 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.17 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.16 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.15 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.14 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.13 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.4.12 app/workers/workarea/bulk_index_searches.rb