From 56f1f13683fed72dbc3d0884ec65d4db8869b5ee Mon Sep 17 00:00:00 2001 From: noellabo Date: Wed, 23 Sep 2020 12:03:01 +0900 Subject: [PATCH] Does not list tags with an underscore at the end --- app/models/tag.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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