class Api::V1::FeaturedTags::SuggestionsController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, only: :index
before_action :require_user!
- before_action :set_most_used_tags, only: :index
+ before_action :set_recently_used_tags, only: :index
def index
- render json: @most_used_tags, each_serializer: REST::TagSerializer
+ render json: @recently_used_tags, each_serializer: REST::TagSerializer
end
private
- def set_most_used_tags
- @most_used_tags = Tag.most_used(current_account).where.not(id: current_account.featured_tags).limit(10)
+ def set_recently_used_tags
+ @recently_used_tags = Tag.recently_used(current_account).where.not(id: current_account.featured_tags).limit(10)
end
end
before_action :authenticate_user!
before_action :set_featured_tags, only: :index
before_action :set_featured_tag, except: [:index, :create]
- before_action :set_most_used_tags, only: :index
+ before_action :set_recently_used_tags, only: :index
def index
@featured_tag = FeaturedTag.new
redirect_to settings_featured_tags_path
else
set_featured_tags
- set_most_used_tags
+ set_recently_used_tags
render :index
end
@featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
end
- def set_most_used_tags
- @most_used_tags = Tag.most_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
+ def set_recently_used_tags
+ @recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
end
def featured_tag_params
scope :listable, -> { where(listable: [true, nil]) }
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
scope :discoverable, -> { listable.joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) }
- scope :most_used, ->(account) { joins(:statuses).where(statuses: { account: account }).group(:id).order(Arel.sql('count(*) desc')) }
+ scope :recently_used, ->(account) { joins(:statuses).where(statuses: { id: account.statuses.select(:id).limit(1000) }).group(:id).order(Arel.sql('count(*) desc')) }
scope :matches_name, ->(value) { where(arel_table[:name].matches("#{value}%")) }
delegate :accounts_count,
= render 'shared/error_messages', object: @featured_tag
.fields-group
- = f.input :name, wrapper: :with_block_label, hint: safe_join([t('simple_form.hints.featured_tag.name'), safe_join(@most_used_tags.map { |tag| link_to("##{tag.name}", settings_featured_tags_path(featured_tag: { name: tag.name }), method: :post) }, ', ')], ' ')
+ = f.input :name, wrapper: :with_block_label, hint: safe_join([t('simple_form.hints.featured_tag.name'), safe_join(@recently_used_tags.map { |tag| link_to("##{tag.name}", settings_featured_tags_path(featured_tag: { name: tag.name }), method: :post) }, ', ')], ' ')
.actions
= f.button :button, t('featured_tags.add_new'), type: :submit