Changed tag most_used to recently_used (#14760)

This commit is contained in:
abcang 2020-09-08 00:47:41 +09:00 committed by GitHub
parent e8bc187845
commit e79d719e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -3,15 +3,15 @@
class Api::V1::FeaturedTags::SuggestionsController < Api::BaseController class Api::V1::FeaturedTags::SuggestionsController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, only: :index before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, only: :index
before_action :require_user! before_action :require_user!
before_action :set_most_used_tags, only: :index before_action :set_recently_used_tags, only: :index
def index def index
render json: @most_used_tags, each_serializer: REST::TagSerializer render json: @recently_used_tags, each_serializer: REST::TagSerializer
end end
private private
def set_most_used_tags def set_recently_used_tags
@most_used_tags = Tag.most_used(current_account).where.not(id: current_account.featured_tags).limit(10) @recently_used_tags = Tag.recently_used(current_account).where.not(id: current_account.featured_tags).limit(10)
end end
end end

View File

@ -6,7 +6,7 @@ class Settings::FeaturedTagsController < Settings::BaseController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_featured_tags, only: :index before_action :set_featured_tags, only: :index
before_action :set_featured_tag, except: [:index, :create] 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 def index
@featured_tag = FeaturedTag.new @featured_tag = FeaturedTag.new
@ -20,7 +20,7 @@ class Settings::FeaturedTagsController < Settings::BaseController
redirect_to settings_featured_tags_path redirect_to settings_featured_tags_path
else else
set_featured_tags set_featured_tags
set_most_used_tags set_recently_used_tags
render :index render :index
end end
@ -41,8 +41,8 @@ class Settings::FeaturedTagsController < Settings::BaseController
@featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?) @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
end end
def set_most_used_tags def set_recently_used_tags
@most_used_tags = Tag.most_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10) @recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
end end
def featured_tag_params def featured_tag_params

View File

@ -39,7 +39,7 @@ class Tag < ApplicationRecord
scope :listable, -> { where(listable: [true, nil]) } scope :listable, -> { where(listable: [true, nil]) }
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) } 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 :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}%")) } scope :matches_name, ->(value) { where(arel_table[:name].matches("#{value}%")) }
delegate :accounts_count, delegate :accounts_count,

View File

@ -9,7 +9,7 @@
= render 'shared/error_messages', object: @featured_tag = render 'shared/error_messages', object: @featured_tag
.fields-group .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 .actions
= f.button :button, t('featured_tags.add_new'), type: :submit = f.button :button, t('featured_tags.add_new'), type: :submit