Sha256: 50e33fedb8a6314741ddca294eb416adc49cefff131e326075d0ad0ead5c4d6c
Contents?: true
Size: 1.47 KB
Versions: 23
Compression:
Stored size: 1.47 KB
Contents
require 'active_support/testing/time_helpers' module Workarea class InsightsSeeds include ActiveSupport::Testing::TimeHelpers def perform puts 'Adding insights...' add_views add_searches add_orders process end def add_views Catalog::Product.limit(100).pluck(:id).each do |id| 12.times do |weeks| travel_to weeks.weeks.ago rand(10).times { Metrics::ProductByDay.inc(key: { product_id: id }, views: 10) } travel_back end end Catalog::Category.limit(100).pluck(:id).each do |id| 12.times do |weeks| travel_to weeks.weeks.ago rand(10).times { Metrics::CategoryByDay.inc(key: { category_id: id }, views: 10) } travel_back end end end def add_searches terms = Catalog::Product .asc(:name) .limit(20) .flat_map { |product| product.name.split(' ') } .uniq terms.each do |term| 12.times do |weeks| travel_to weeks.weeks.ago rand(3).times { Metrics::SearchByDay.save_search(term, 0) } rand(3).times do Metrics::SearchByDay.save_search(term, rand(100)) end travel_back end end end def add_orders Order.all.each_by(1000) { |order| SaveOrderMetrics.perform(order) } end def process ProcessProductRecommendations.new.perform GenerateInsights.generate_all! end end end
Version data entries
23 entries across 23 versions & 1 rubygems