forked from fedi/mastodon
Fix trending tags returning less items than requested sometimes (#11513)
Add better sorting defaults to the hashtags admin UI Add "not reviewed" filter to hashtags admin UI
This commit is contained in:
parent
7a737c79cc
commit
94c54997cf
|
@ -36,9 +36,10 @@ module Admin
|
||||||
def filtered_tags
|
def filtered_tags
|
||||||
scope = Tag
|
scope = Tag
|
||||||
scope = scope.discoverable if filter_params[:context] == 'directory'
|
scope = scope.discoverable if filter_params[:context] == 'directory'
|
||||||
scope = scope.reviewed if filter_params[:review] == 'reviewed'
|
scope = scope.unreviewed if filter_params[:review] == 'unreviewed'
|
||||||
scope = scope.pending_review if filter_params[:review] == 'pending_review'
|
scope = scope.reviewed.order(reviewed_at: :desc) if filter_params[:review] == 'reviewed'
|
||||||
scope.reorder(score: :desc)
|
scope = scope.pending_review.order(requested_review_at: :desc) if filter_params[:review] == 'pending_review'
|
||||||
|
scope.order(score: :desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_params
|
def filter_params
|
||||||
|
|
|
@ -30,7 +30,8 @@ class Tag < ApplicationRecord
|
||||||
validate :validate_name_change, if: -> { !new_record? && name_changed? }
|
validate :validate_name_change, if: -> { !new_record? && name_changed? }
|
||||||
|
|
||||||
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
||||||
scope :pending_review, -> { where(reviewed_at: nil).where.not(requested_review_at: nil) }
|
scope :unreviewed, -> { where(reviewed_at: nil) }
|
||||||
|
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
|
||||||
scope :usable, -> { where(usable: [true, nil]) }
|
scope :usable, -> { where(usable: [true, nil]) }
|
||||||
scope :discoverable, -> { where(listable: [true, nil]).joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) }
|
scope :discoverable, -> { where(listable: [true, nil]).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 :most_used, ->(account) { joins(:statuses).where(statuses: { account: account }).group(:id).order(Arel.sql('count(*) desc')) }
|
||||||
|
|
|
@ -5,6 +5,7 @@ class TrendingTags
|
||||||
EXPIRE_HISTORY_AFTER = 7.days.seconds
|
EXPIRE_HISTORY_AFTER = 7.days.seconds
|
||||||
EXPIRE_TRENDS_AFTER = 1.day.seconds
|
EXPIRE_TRENDS_AFTER = 1.day.seconds
|
||||||
THRESHOLD = 5
|
THRESHOLD = 5
|
||||||
|
LIMIT = 10
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
include Redisable
|
include Redisable
|
||||||
|
@ -18,18 +19,18 @@ class TrendingTags
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(limit, filtered: true)
|
def get(limit, filtered: true)
|
||||||
tag_ids = redis.zrevrange("#{KEY}:#{Time.now.utc.beginning_of_day.to_i}", 0, limit - 1).map(&:to_i)
|
tag_ids = redis.zrevrange("#{KEY}:#{Time.now.utc.beginning_of_day.to_i}", 0, LIMIT - 1).map(&:to_i)
|
||||||
|
|
||||||
tags = Tag.where(id: tag_ids)
|
tags = Tag.where(id: tag_ids)
|
||||||
tags = tags.where(trendable: true) if filtered
|
tags = tags.where(trendable: true) if filtered
|
||||||
tags = tags.each_with_object({}) { |tag, h| h[tag.id] = tag }
|
tags = tags.each_with_object({}) { |tag, h| h[tag.id] = tag }
|
||||||
|
|
||||||
tag_ids.map { |tag_id| tags[tag_id] }.compact
|
tag_ids.map { |tag_id| tags[tag_id] }.compact.take(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def trending?(tag)
|
def trending?(tag)
|
||||||
rank = redis.zrevrank("#{KEY}:#{Time.now.utc.beginning_of_day.to_i}", tag.id)
|
rank = redis.zrevrank("#{KEY}:#{Time.now.utc.beginning_of_day.to_i}", tag.id)
|
||||||
rank.present? && rank <= 10
|
rank.present? && rank <= LIMIT
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -59,7 +60,7 @@ class TrendingTags
|
||||||
old_rank = redis.zrevrank(key, tag.id)
|
old_rank = redis.zrevrank(key, tag.id)
|
||||||
|
|
||||||
redis.zadd(key, score, tag.id)
|
redis.zadd(key, score, tag.id)
|
||||||
request_review!(tag) if (old_rank.nil? || old_rank > 10) && redis.zrevrank(key, tag.id) <= 10 && !tag.trendable? && tag.requires_review? && !tag.requested_review?
|
request_review!(tag) if (old_rank.nil? || old_rank > LIMIT) && redis.zrevrank(key, tag.id) <= LIMIT && !tag.trendable? && tag.requires_review? && !tag.requested_review?
|
||||||
end
|
end
|
||||||
|
|
||||||
redis.expire(key, EXPIRE_TRENDS_AFTER)
|
redis.expire(key, EXPIRE_TRENDS_AFTER)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
%strong= t('admin.tags.review')
|
%strong= t('admin.tags.review')
|
||||||
%ul
|
%ul
|
||||||
%li= filter_link_to t('generic.all'), review: nil
|
%li= filter_link_to t('generic.all'), review: nil
|
||||||
|
%li= filter_link_to t('admin.tags.unreviewed'), review: 'unreviewed'
|
||||||
%li= filter_link_to t('admin.tags.reviewed'), review: 'reviewed'
|
%li= filter_link_to t('admin.tags.reviewed'), review: 'reviewed'
|
||||||
%li= filter_link_to safe_join([t('admin.accounts.moderation.pending'), "(#{Tag.pending_review.count})"], ' '), review: 'pending_review'
|
%li= filter_link_to safe_join([t('admin.accounts.moderation.pending'), "(#{Tag.pending_review.count})"], ' '), review: 'pending_review'
|
||||||
|
|
||||||
|
|
|
@ -498,6 +498,7 @@ en:
|
||||||
title: Hashtags
|
title: Hashtags
|
||||||
trending_right_now: Trending right now
|
trending_right_now: Trending right now
|
||||||
unique_uses_today: "%{count} posting today"
|
unique_uses_today: "%{count} posting today"
|
||||||
|
unreviewed: Not reviewed
|
||||||
updated_msg: Hashtag settings updated successfully
|
updated_msg: Hashtag settings updated successfully
|
||||||
title: Administration
|
title: Administration
|
||||||
warning_presets:
|
warning_presets:
|
||||||
|
|
Loading…
Reference in a new issue