Sha256: 125f4caa9090e903f077e4213e2b6e2f654812b07c277a8cb8d2fbaab6ce1370

Contents?: true

Size: 747 Bytes

Versions: 28

Compression:

Stored size: 747 Bytes

Contents

module Workarea
  class ProcessSearchRecommendations
    include Sidekiq::Worker

    def perform(*)
      predictor.clean!

      start = Workarea.config.recommendation_expiration.ago

      Metrics::User
        .where(:updated_at.gte => start)
        .desc(:updated_at) # sort by updated_at to ensure use of that index
        .each_by(page_size) { |metrics| add(metrics) }

      predictor.process!
    end

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

    def add(metrics)
      return unless metrics.viewed.search_ids.many?
      predictor.sessions.add_set(metrics.id, metrics.viewed.search_ids)
    end

    def page_size
      Workarea.config.search_recommendation_index_page_size
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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