delegate removal from favorites and updating of user fav counts to delayed job
This commit is contained in:
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user