From ab325d48bfad8af11537fbfbabc02964bceda2f0 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 7 Dec 2015 14:39:46 -0800 Subject: [PATCH] optimize favorite delete, ignore statement timeout when expunging posts #2556 --- app/models/favorite.rb | 2 +- app/models/post.rb | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/models/favorite.rb b/app/models/favorite.rb index c0ff859a2..9d894ef7a 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -34,7 +34,7 @@ class Favorite < ActiveRecord::Base User.where(:id => user.id).select("id").lock("FOR UPDATE NOWAIT").first 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) + Favorite.for_user(user.id).where(post_id: post.id).delete_all updates = "fav_count = fav_count - 1" updates = "#{updates}, score = score - 1" if user.is_gold? Post.where(:id => post.id).update_all(updates) diff --git a/app/models/post.rb b/app/models/post.rb index 78770ca55..3a89cca69 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1194,12 +1194,14 @@ class Post < ActiveRecord::Base ModAction.create(:description => "permanently deleted post ##{id}") delete!(:without_mod_action => true) - give_favorites_to_parent - update_children_on_destroy - decrement_tag_post_counts - remove_from_all_pools - destroy - update_parent_on_destroy + Post.without_timeout do + give_favorites_to_parent + update_children_on_destroy + decrement_tag_post_counts + remove_from_all_pools + destroy + update_parent_on_destroy + end end def ban!