Skip to content

Instantly share code, notes, and snippets.

@john-bai
Created August 1, 2013 09:46
Show Gist options
  • Select an option

  • Save john-bai/6129968 to your computer and use it in GitHub Desktop.

Select an option

Save john-bai/6129968 to your computer and use it in GitHub Desktop.
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 25
username: notmyrealusername
password: notmyrealpassword
class Review < UserEvent
belongs_to :user, counter_cache: true
belongs_to :item, counter_cache: true
after_commit :submit_compute_jobs, if: :persisted?
private
def submit_compute_jobs
SimilarityComputeJobCreator.perform_async(id)
end
end
Item.all.each_with_index do |item, index|
users.sample(20).each do |user|
review = Review.new(rating: 1 + rand(5))
review.user = user
review.item = item
review.place = item.place
review.save
end
end
class SimilarityComputeJob < ActiveRecord::Base
attr_accessible :item1_id, :item2_id
end
class SimilarityComputeJobCreator
include Sidekiq::Worker
def perform(review_id)
review = Review.find review_id
user_reviews = review.user.reviews
if user_reviews.count > 1
# create SimilarityComputeJobs for this review and the user's other reviews
user_reviews.each do |other_review|
unless review.id == other_review.id
item1_id, item2_id = [review.item_id, other_review.item_id].sort
SimilarityComputeJob.create(item1_id: item1_id, item2_id: item2_id)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment