fix favcount
This commit is contained in:
@@ -207,6 +207,12 @@ class PostQueryBuilder
|
||||
|
||||
when "score_asc"
|
||||
relation = relation.order("posts.score, posts.id DESC")
|
||||
|
||||
when "favcount"
|
||||
relation = relation.order("posts.fav_count DESC, posts.id DESC")
|
||||
|
||||
when "favcount_asc"
|
||||
relation = relation.order("posts.fav_count, posts.id DESC")
|
||||
|
||||
when "mpixels", "mpixels_desc"
|
||||
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
|
||||
|
||||
@@ -490,6 +490,7 @@ class Post < ActiveRecord::Base
|
||||
def add_favorite!(user)
|
||||
return if favorited_by?(user.id)
|
||||
append_user_to_fav_string(user.id)
|
||||
increment!(:fav_count)
|
||||
user.add_favorite!(self)
|
||||
end
|
||||
|
||||
@@ -499,6 +500,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
def remove_favorite!(user)
|
||||
return unless favorited_by?(user.id)
|
||||
decrement!(:fav_count)
|
||||
delete_user_from_fav_string(user.id)
|
||||
user.remove_favorite!(self)
|
||||
end
|
||||
|
||||
2
script/fixes/003.sql
Normal file
2
script/fixes/003.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
set statement_timeout = 0;
|
||||
update posts set fav_count = (select count(*) from favorites _ where _.post_id = posts.id) where posts.created_at > '2013-02-01';
|
||||
Reference in New Issue
Block a user