fix favcount
This commit is contained in:
@@ -208,6 +208,12 @@ class PostQueryBuilder
|
|||||||
when "score_asc"
|
when "score_asc"
|
||||||
relation = relation.order("posts.score, posts.id DESC")
|
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"
|
when "mpixels", "mpixels_desc"
|
||||||
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
|
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
|
||||||
# the posts_mpixels index.
|
# the posts_mpixels index.
|
||||||
|
|||||||
@@ -490,6 +490,7 @@ class Post < ActiveRecord::Base
|
|||||||
def add_favorite!(user)
|
def add_favorite!(user)
|
||||||
return if favorited_by?(user.id)
|
return if favorited_by?(user.id)
|
||||||
append_user_to_fav_string(user.id)
|
append_user_to_fav_string(user.id)
|
||||||
|
increment!(:fav_count)
|
||||||
user.add_favorite!(self)
|
user.add_favorite!(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -499,6 +500,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
def remove_favorite!(user)
|
def remove_favorite!(user)
|
||||||
return unless favorited_by?(user.id)
|
return unless favorited_by?(user.id)
|
||||||
|
decrement!(:fav_count)
|
||||||
delete_user_from_fav_string(user.id)
|
delete_user_from_fav_string(user.id)
|
||||||
user.remove_favorite!(self)
|
user.remove_favorite!(self)
|
||||||
end
|
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