From 80ced3e41857c6339d119543ee0b6f1cd66e742c Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 21 May 2022 14:02:01 -0500 Subject: [PATCH] posts: fix rounding errors in ratio: metatag. Fix the ratio: metatag sometimes including wrong results due to rounding errors. For example, searching for `ratio:>=4.0` would include post 3220414, which has an aspect ratio of 3.99879. This would get rounded up to 2 decimal places to 4.00. --- app/logical/post_query_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index de602fd96..ccfd0530a 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -98,7 +98,7 @@ class PostQueryBuilder when "mpixels" relation.attribute_matches(value, "posts.image_width * posts.image_height / 1000000.0", :float) when "ratio" - relation.attribute_matches(value, "ROUND(1.0 * posts.image_width / GREATEST(1, posts.image_height), 2)", :ratio) + relation.attribute_matches(value, "posts.image_width::numeric / posts.image_height::numeric", :ratio) when "score" relation.attribute_matches(value, :score) when "upvotes"