Sha256: 1a5eb0e322672f61275cb2402067c8d476d4a1c87b2a493044948cd17323cc82

Contents?: true

Size: 739 Bytes

Versions: 62

Compression:

Stored size: 739 Bytes

Contents

module Workarea
  class ProcessProductRecommendations
    include Sidekiq::Worker

    def perform(*)
      predictor.clean!

      start = Workarea.config.recommendation_expiration.ago

      Order
        .where(:placed_at.gte => start)
        .desc(:placed_at) # sort by placed_at to ensure use of that index
        .each_by(page_size) { |order| add(order) }

      predictor.process!
    end

    def predictor
      @predictor ||= Recommendation::ProductPredictor.new
    end

    def add(order)
      product_ids = order.items.map(&:product_id)
      predictor.orders.add_set(order.id.to_s, product_ids) if product_ids.many?
    end

    def page_size
      Workarea.config.product_recommendation_index_page_size
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.36 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.14 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.35 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.13 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.34 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.12 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.33 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.11 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.10 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.32 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.9 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.31 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.8 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.30 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.7 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.29 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.6 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.4.28 app/workers/workarea/process_product_recommendations.rb
workarea-core-3.5.5 app/workers/workarea/process_product_recommendations.rb