Sha256: b65b05e0d419997676c41d18ec10b9913afaa05b25f08b82d0cb2eb5e1ed139f

Contents?: true

Size: 782 Bytes

Versions: 18

Compression:

Stored size: 782 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)
        Search::Storefront.bulk do
          searches.map do |model|
            Search::Storefront::Search.new(model).as_bulk_document
          end
        end
      end
    end

    def perform(*)
      self.class.perform
    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_searches.rb
workarea-core-3.5.26 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.25 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.23 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.22 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.21 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.20 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.19 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.18 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.17 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.16 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.15 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.14 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.13 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.12 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.11 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.10 app/workers/workarea/bulk_index_searches.rb
workarea-core-3.5.9 app/workers/workarea/bulk_index_searches.rb