このコミットが含まれているのは:
2026-03-08 15:24:41 +09:00
コミット 613b668843
+9 -10
ファイルの表示
@@ -48,7 +48,7 @@ class Tag < ApplicationRecord
validate :tag_name_must_be_canonical validate :tag_name_must_be_canonical
validate :category_must_be_deerjikist_with_deerjikists validate :category_must_be_deerjikist_with_deerjikists
scope :nico_tags, -> { where(category: :nico) } scope :nico_tags, -> { nico }
CATEGORY_PREFIXES = { CATEGORY_PREFIXES = {
'general:' => :general, 'general:' => :general,
@@ -97,14 +97,12 @@ class Tag < ApplicationRecord
pf, cat = CATEGORY_PREFIXES.find { |p, _| name.downcase.start_with?(p) } || ['', nil] pf, cat = CATEGORY_PREFIXES.find { |p, _| name.downcase.start_with?(p) } || ['', nil]
name = TagName.canonicalise(name.sub(/\A#{ pf }/i, '')).first name = TagName.canonicalise(name.sub(/\A#{ pf }/i, '')).first
find_or_create_by_tag_name!(name, category: (cat || :general)).tap do |tag| find_or_create_by_tag_name!(name, category: (cat || :general)).tap do |tag|
if cat && tag.category != cat tag.update!(category: cat) if cat && tag.category != cat
tag.update!(category: cat)
end
end end
end end
tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme) tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme)
tags << Tag.no_deerjikist if tags.all? { |t| t.category != 'deerjikist' } tags << Tag.no_deerjikist if tags.all? { |t| !(t.deerjikist?) }
tags.uniq(&:id) tags.uniq(&:id)
end end
@@ -166,19 +164,20 @@ class Tag < ApplicationRecord
tag_name.reload tag_name.reload
tag_name.update!(canonical: target_tag.tag_name) tag_name.update!(canonical: target_tag.tag_name)
end end
# 再集計
target_tag.update_columns(post_count: PostTag.kept.where(tag: target_tag).count)
end end
target_tag.update!(post_count: PostTag.kept.where(tag: target_tag).count) target_tag.reload
target_tag
end end
private private
def nico_tag_name_must_start_with_nico def nico_tag_name_must_start_with_nico
n = name.to_s n = name.to_s
if ((category == 'nico' && !(n.downcase.start_with?('nico:'))) || if ((nico? && !(n.downcase.start_with?('nico:'))) ||
(category != 'nico' && n.downcase.start_with?('nico:'))) (!(nico?) && n.downcase.start_with?('nico:')))
errors.add :name, 'ニコニコ・タグの命名規則に反してゐます.' errors.add :name, 'ニコニコ・タグの命名規則に反してゐます.'
end end
end end