From 46e623506dcc5d31e07011007a5c85e16f60ceb2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 5 Mar 2024 09:56:58 -0500 Subject: [PATCH] Add `FeaturedTag.by_status_count` ordering scope --- app/controllers/api/v1/featured_tags_controller.rb | 2 +- app/controllers/settings/featured_tags_controller.rb | 2 +- app/models/featured_tag.rb | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/featured_tags_controller.rb b/app/controllers/api/v1/featured_tags_controller.rb index 516046f009..a828428274 100644 --- a/app/controllers/api/v1/featured_tags_controller.rb +++ b/app/controllers/api/v1/featured_tags_controller.rb @@ -29,6 +29,6 @@ class Api::V1::FeaturedTagsController < Api::BaseController end def set_featured_tags - @featured_tags = current_account.featured_tags.order(statuses_count: :desc) + @featured_tags = current_account.featured_tags.by_status_count end end diff --git a/app/controllers/settings/featured_tags_controller.rb b/app/controllers/settings/featured_tags_controller.rb index 7e29dd1d29..b50fe56d64 100644 --- a/app/controllers/settings/featured_tags_controller.rb +++ b/app/controllers/settings/featured_tags_controller.rb @@ -36,7 +36,7 @@ class Settings::FeaturedTagsController < Settings::BaseController end def set_featured_tags - @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?) + @featured_tags = current_account.featured_tags.by_status_count.reject(&:new_record?) end def set_recently_used_tags diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index 529056f9c6..345d2c3202 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -29,6 +29,7 @@ class FeaturedTag < ApplicationRecord before_create :reset_data scope :by_name, ->(name) { joins(:tag).where(tag: { name: HashtagNormalizer.new.normalize(name) }) } + scope :by_status_count, -> { order(statuses_count: :desc) } LIMIT = 10