delegate removal from favorites and updating of user fav counts to delayed job

This commit is contained in:
r888888888
2017-09-13 14:19:54 -07:00
parent 5a6cc84817
commit 1f3bafc061
4 changed files with 28 additions and 18 deletions

View File

@@ -14,10 +14,17 @@ class Favorite < ApplicationRecord
post.append_user_to_fav_string(user.id)
User.where(:id => user.id).update_all("favorite_count = favorite_count + 1")
user.favorite_count += 1
# post.fav_count += 1 # this is handled in Post#clean_fav_string!
end
end
def self.purge_post(post_id, user_ids)
0.upto(99) do |uid|
Favorite.where("user_id % 100 = ?", uid).delete_all(post_id: post_id)
end
User.where(:id => user_ids).update_all("favorite_count = favorite_count - 1")
end
def self.remove(user:, post: nil, post_id: nil)
Favorite.transaction do
if post && post_id.nil?