From e15fb6eac9324f8367be6c7f5e595e3571a0ce5d Mon Sep 17 00:00:00 2001 From: r888888888 Date: Sun, 22 Jun 2014 19:43:17 -0700 Subject: [PATCH] Revert "potential fix for #1210" This reverts commit d5f10f41fd64543c6dbe9d7773f19b5c1dd8ac98. --- app/models/favorite.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 65eb9f158..06bd08bb8 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -14,13 +14,10 @@ class Favorite < ActiveRecord::Base def self.add(post, user) Favorite.transaction do - return if Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post.id).lock("FOR UPDATE NOWAIT").exists? + return if Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post.id).exists? Favorite.create!(:user_id => user.id, :post_id => post.id) - changes = "fav_count = fav_count + 1" - if user.is_gold? - changes = "#{changes}, score = score + 1" - end - Post.where(:id => post.id).update_all(changes) + Post.where(:id => post.id).update_all("fav_count = fav_count + 1") + Post.where(:id => post.id).update_all("score = score + 1") if user.is_gold? post.append_user_to_fav_string(user.id) User.where(:id => user.id).update_all("favorite_count = favorite_count + 1") user.favorite_count += 1 @@ -31,7 +28,7 @@ class Favorite < ActiveRecord::Base def self.remove(post, user) Favorite.transaction do - return unless Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post.id).lock("FOR UPDATE NOWAIT").exists? + return unless Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post.id).exists? Favorite.destroy_all(:user_id => user.id, :post_id => post.id) Post.where(:id => post.id).update_all("fav_count = fav_count - 1") Post.where(:id => post.id).update_all("Score = score - 1") if user.is_gold?