diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 63e74f02d..88d77bc09 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -542,7 +542,9 @@ class PostQueryBuilder # better. def optimize_search(relation, small_search_threshold) return relation unless small_search_threshold.present? - return relation unless relation.order_values.map(&:downcase).in?([["posts.id desc"], ["posts.id asc"]]) + + order_values = relation.order_values.map { |order| order.try(:to_sql) || order.to_s }.map(&:downcase) + return relation unless order_values.in?([["posts.id desc"], ["posts.id asc"]]) if post_count.nil? # If post_count is nil, then the search took too long to count and we don't diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index a9bcf36bc..f4a0c1645 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -323,6 +323,9 @@ class PostsControllerTest < ActionDispatch::IntegrationTest get posts_path, params: { tags: "order:random" } assert_response :success + get posts_path(tags: "random:1") + assert_response :success + get posts_path(random: "1") assert_redirected_to posts_path(tags: "random:20", format: :html)