From 0684118008837c0f55a689490bb20257b72ae36c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 21 Aug 2020 14:39:07 +0800 Subject: [PATCH] DEV: Remove array_agg from search orders that does not need it. --- lib/search.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/search.rb b/lib/search.rb index 316ff535714..c53a94261fd 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -933,33 +933,33 @@ class Search if aggregate_search aggregate_relation = aggregate_relation .select( - "(ARRAY_AGG(subquery.post_number ORDER BY subquery.created_at DESC))[1] post_number", + "MAX(subquery.post_number) post_number", "MAX(subquery.created_at) created_at" ) .order("created_at DESC") end elsif @order == :latest_topic - posts = posts.order("topic_created_at DESC") + posts = posts.order("topics.created_at DESC") if aggregate_search posts = posts.select("topics.created_at topic_created_at") aggregate_relation = aggregate_relation .select( - "(ARRAY_AGG(subquery.post_number ORDER BY subquery.topic_created_at DESC))[1] post_number", + "MIN(subquery.post_number) post_number", "MAX(subquery.topic_created_at) topic_created_at" ) .order("topic_created_at DESC") end elsif @order == :views - posts = posts.order("topic_views DESC") + posts = posts.order("topics.views DESC") if aggregate_search posts = posts.select("topics.views topic_views") aggregate_relation = aggregate_relation .select( - "(ARRAY_AGG(subquery.post_number ORDER BY subquery.topic_views DESC))[1] post_number", + "MIN(subquery.post_number) post_number", "MAX(subquery.topic_views) topic_views" ) .order("topic_views DESC")