diff --git a/app/models/tag.rb b/app/models/tag.rb index 45de576e6..f083760bb 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -41,6 +41,8 @@ class Tag < ApplicationRecord 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, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index + before_save :set_unlistable, if: :force_unlistable? + update_index('tags#tag', :self) def to_param @@ -65,6 +67,10 @@ class Tag < ApplicationRecord alias trendable? trendable + def force_unlistable? + name.end_with?('_') + end + def requires_review? reviewed_at.nil? end @@ -148,6 +154,10 @@ class Tag < ApplicationRecord private + def set_unlistable + self.listable = false + end + def validate_name_change errors.add(:name, I18n.t('tags.does_not_match_previous_name')) unless name_was.mb_chars.casecmp(name.mb_chars).zero? end