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

@@ -172,18 +172,24 @@ class FavoriteGroup < ApplicationRecord
self.post_count = post_id_array.size
end
def add!(post)
return if contains?(post.id)
def add!(post_id)
return if contains?(post_id)
clear_post_id_array
update_attributes(:post_ids => add_number_to_string(post.id, post_ids))
update_attributes(:post_ids => add_number_to_string(post_id, post_ids))
end
def remove!(post)
return unless contains?(post.id)
def self.purge_post(post_id)
for_post(post_id).find_each do |group|
group.remove!(post_id)
end
end
def remove!(post_id)
return unless contains?(post_id)
clear_post_id_array
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids))
update_attributes(:post_ids => remove_number_from_string(post_id, post_ids))
end
def add_number_to_string(number, string)