From c901eb48be37d34dea509182088e4b22ace15f38 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Thu, 29 Feb 2024 18:27:47 -0500 Subject: [PATCH] Apply efficiency adjustment to orgs as well (#20710) --- app/queries/organizations/suggest_prominent.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/queries/organizations/suggest_prominent.rb b/app/queries/organizations/suggest_prominent.rb index 0de47a50c..af25b069f 100644 --- a/app/queries/organizations/suggest_prominent.rb +++ b/app/queries/organizations/suggest_prominent.rb @@ -13,8 +13,7 @@ module Organizations def suggest return [] if tags_to_consider.empty? - filtered_articles = Article.cached_tagged_with_any(tags_to_consider).where.not(organization_id: nil) - org_ids = fetch_and_pluck_org_ids(filtered_articles) + org_ids = fetch_and_pluck_org_ids Organization.where(id: org_ids.uniq).order(Arel.sql("RANDOM()")).limit(MAX) end @@ -26,9 +25,9 @@ module Organizations user.decorate.cached_followed_tag_names end - def fetch_and_pluck_org_ids(filtered_articles) - order = Arel.sql("(hotness_score * (feed_success_score - clickbait_score)) DESC") - filtered_articles.order(order).limit(MAX * 2).pluck(:organization_id) + def fetch_and_pluck_org_ids + Article.published.cached_tagged_with_any(tags_to_consider).where.not(organization_id: nil) + .order("hotness_score DESC").limit(MAX * 2).pluck(:organization_id) end end end