added cached columns for post update count, post upload count, note update count, favorite count to users; fixed tests
This commit is contained in:
@@ -182,12 +182,14 @@ class User < ActiveRecord::Base
|
||||
def add_favorite!(post)
|
||||
return if Favorite.exists?(:user_id => id, :post_id => post.id)
|
||||
Favorite.create(:user_id => id, :post_id => post.id)
|
||||
increment!(:favorite_count)
|
||||
post.add_favorite!(self)
|
||||
end
|
||||
|
||||
def remove_favorite!(post)
|
||||
return unless Favorite.exists?(:user_id => id, :post_id => post.id)
|
||||
Favorite.destroy_all(:user_id => id, :post_id => post.id)
|
||||
decrement!(:favorite_count)
|
||||
post.remove_favorite!(self)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user