Does not list tags with an underscore at the end

This commit is contained in:
noellabo 2020-09-23 12:03:01 +09:00
parent 2f88e910b6
commit 56f1f13683

View file

@ -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