simplify logic
This commit is contained in:
@@ -17,14 +17,6 @@ class Favorite < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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)
|
def self.remove(user:, post: nil, post_id: nil)
|
||||||
Favorite.transaction do
|
Favorite.transaction do
|
||||||
if post && post_id.nil?
|
if post && post_id.nil?
|
||||||
|
|||||||
@@ -1038,7 +1038,9 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_from_favorites
|
def remove_from_favorites
|
||||||
Favorite.delay.purge_post(id, fav_string.scan(/\d+/))
|
Favorite.delete_all(post_id: id)
|
||||||
|
user_ids = fav_string.scan(/\d+/)
|
||||||
|
User.where(:id => user_ids).update_all("favorite_count = favorite_count - 1")
|
||||||
PostVote.where(post_id: id).delete_all
|
PostVote.where(post_id: id).delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user