Created
August 1, 2013 09:46
-
-
Save john-bai/6129968 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| development: | |
| adapter: postgresql | |
| encoding: unicode | |
| database: app_development | |
| pool: 25 | |
| username: notmyrealusername | |
| password: notmyrealpassword |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SimilarityComputeJob < ActiveRecord::Base | |
| attr_accessible :item1_id, :item2_id | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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