Change featured tag recommendations (#39567)
This commit is contained in:
1 parent
be250ae368
commit
d8b2668837
2 files changed
+9
-2
No files matched your search
+3
-2
@@ -46,6 +46,7 @@ class Tag < ApplicationRecord
|
||||
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]\u0E47-\u0E4E#{HASHTAG_SEPARATORS}]/
|
||||
|
||||
RECENT_STATUS_LIMIT = 1000
|
||||
RECENT_STATUS_MAX_AGE = 1.year
|
||||
|
||||
validates :name, presence: true, format: { with: HASHTAG_NAME_RE }
|
||||
validates :display_name, format: { with: HASHTAG_NAME_RE }
|
||||
@@ -58,11 +59,11 @@ class Tag < ApplicationRecord
|
||||
scope :listable, -> { where(listable: [true, nil]) }
|
||||
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
|
||||
scope :not_trendable, -> { where(trendable: false) }
|
||||
scope :suggestions_for_account, ->(account) { recently_used(account).not_featured_by(account) }
|
||||
scope :suggestions_for_account, ->(account) { recently_used(account).having('count(statuses.id) > 1').not_featured_by(account) }
|
||||
scope :not_featured_by, ->(account) { where.not(id: account.featured_tags.select(:tag_id)) }
|
||||
scope :recently_used, lambda { |account|
|
||||
joins(:statuses)
|
||||
.where(statuses: { id: account.statuses.select(:id).limit(RECENT_STATUS_LIMIT) })
|
||||
.where(statuses: { id: account.statuses.select(:id).where(id: (Mastodon::Snowflake.id_at(RECENT_STATUS_MAX_AGE.ago)..)).limit(RECENT_STATUS_LIMIT) })
|
||||
.group(:id).order(Arel.star.count.desc)
|
||||
}
|
||||
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(normalize_value_for(:name, term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
|
||||
|
||||
@@ -12,6 +12,7 @@ RSpec.describe 'Featured Tags Suggestions API' do
|
||||
describe 'GET /api/v1/featured_tags/suggestions' do
|
||||
let!(:unused_featured_tag) { Fabricate(:tag, name: 'unused_featured_tag') }
|
||||
let!(:used_tag) { Fabricate(:tag, name: 'used_tag') }
|
||||
let!(:used_tag_once) { Fabricate(:tag, name: 'used_tag_once') }
|
||||
let!(:used_featured_tag) { Fabricate(:tag, name: 'used_featured_tag') }
|
||||
|
||||
before do
|
||||
@@ -20,8 +21,13 @@ RSpec.describe 'Featured Tags Suggestions API' do
|
||||
# Make relevant tags used by account
|
||||
status = Fabricate(:status, account: account)
|
||||
status.tags << used_tag
|
||||
status.tags << used_tag_once
|
||||
status.tags << used_featured_tag
|
||||
|
||||
status2 = Fabricate(:status, account: account)
|
||||
status2.tags << used_tag
|
||||
status2.tags << used_featured_tag
|
||||
|
||||
# Feature the relevant tags
|
||||
Fabricate :featured_tag, account: account, name: unused_featured_tag.name
|
||||
Fabricate :featured_tag, account: account, name: used_featured_tag.name
|
||||
|
||||
Reference in new issue
Block a user