Revert "remove mpixel search, remove some unused indexes on posts"

This reverts commit 11e550c385.
This commit is contained in:
r888888888
2015-01-18 22:56:02 -08:00
parent 7ad7101bc2
commit 5063e326e3
7 changed files with 123 additions and 102 deletions

View File

@@ -119,6 +119,7 @@ class PostQueryBuilder
end
relation = add_range_relation(q[:post_id], "posts.id", relation)
relation = add_range_relation(q[:mpixels], "posts.image_width * posts.image_height / 1000000.0", relation)
relation = add_range_relation(q[:ratio], "ROUND(1.0 * posts.image_width / GREATEST(1, posts.image_height), 2)", relation)
relation = add_range_relation(q[:width], "posts.image_width", relation)
relation = add_range_relation(q[:height], "posts.image_height", relation)
@@ -368,6 +369,16 @@ class PostQueryBuilder
relation = relation.joins("INNER JOIN artist_commentaries ON artist_commentaries.post_id = posts.id")
relation = relation.order("artist_commentaries.updated_at ASC, posts.id DESC")
when "mpixels", "mpixels_desc"
relation = relation.where("posts.image_width is not null and posts.image_height is not null")
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
# the posts_mpixels index.
relation = relation.order("posts.image_width * posts.image_height / 1000000.0 DESC, posts.id DESC")
when "mpixels_asc"
relation = relation.where("posts.image_width is not null and posts.image_height is not null")
relation = relation.order("posts.image_width * posts.image_height / 1000000.0 ASC, posts.id DESC")
when "portrait"
relation = relation.order("1.0 * posts.image_width / GREATEST(1, posts.image_height) ASC, posts.id DESC")