このコミットが含まれているのは:
2026-09-28 01:15:00 +09:00
コミット 56b656109d
14個のファイルの変更、109行の追加、28行の削除
+3 -1
ファイルの表示
@@ -689,6 +689,7 @@ class PostsController < ApplicationController
version.tags_json
.select { _1.key?('tag_id') }
.map { Post.tag_snapshot_literal(_1) }
.compact
.sort
end
@@ -716,7 +717,7 @@ class PostsController < ApplicationController
next name if sections.empty?
"#{ name }#{ sections.map { Post.section_literal(_1) }.join }"
end
end.compact.sort
end
def post_incoming_snapshot locale:, title:, original_created_from:, original_created_before:,
@@ -725,6 +726,7 @@ class PostsController < ApplicationController
Tag.normalise_tags!(locale, tag_names,
with_tagme: false,
with_no_deerjikist: false,
deny_deprecated: true,
with_sections: true) => { tags:, sections: }
+15 -4
ファイルの表示
@@ -19,7 +19,8 @@ class TagVersionsController < ApplicationController
SQL
.select('tag_versions.*', 'prev.name AS prev_name', 'prev.category AS prev_category',
'prev.deprecated_at AS prev_deprecated_at',
'prev.aliases AS prev_aliases', 'prev.parent_tag_ids AS prev_parent_tag_ids')
'prev.aliases AS prev_aliases', 'prev.names AS prev_names',
'prev.parent_tag_ids AS prev_parent_tag_ids')
q = q.where('tag_versions.tag_id = ?', tag_id) if tag_id
count = q.except(:select, :order, :limit, :offset).count
@@ -38,8 +39,10 @@ class TagVersionsController < ApplicationController
users_by_id = User.where(id: user_ids).pluck(:id, :name).to_h
rows.map do |row|
cur_aliases = split_values(row.aliases)
prev_aliases = split_values(row.attributes['prev_aliases'])
current_names = names_for_locale(row.names, language_code)
previous_names = names_for_locale(row.attributes['prev_names'], language_code)
cur_aliases = current_names.reject { _1['primary_flg'] }.map { _1['name'] }
prev_aliases = previous_names.reject { _1['primary_flg'] }.map { _1['name'] }
cur_parent_tag_ids = split_parent_tag_ids(row.parent_tag_ids)
prev_parent_tag_ids = split_parent_tag_ids(row.attributes['prev_parent_tag_ids'])
@@ -63,7 +66,8 @@ class TagVersionsController < ApplicationController
version_no: row.version_no,
event_type: row.event_type,
names: row.names,
name: { current: row.name, prev: row.attributes['prev_name'] },
name: { current: current_names.find { _1['primary_flg'] }&.fetch('name'),
prev: previous_names.find { _1['primary_flg'] }&.fetch('name') },
category: { current: row.category, prev: row.attributes['prev_category'] },
deprecated_at: { current: row.deprecated_at&.iso8601,
prev: row.attributes['prev_deprecated_at']&.iso8601 },
@@ -93,5 +97,12 @@ class TagVersionsController < ApplicationController
def split_values(values) = values.to_s.split(/\s+/).reject(&:blank?)
def names_for_locale names, language_code
values = names.is_a?(String) ? JSON.parse(names) : Array(names)
values.select { _1['language_code'] == language_code }
rescue JSON::ParserError
[]
end
def split_parent_tag_ids(values) = split_values(values).map(&:to_i)
end
+8 -3
ファイルの表示
@@ -473,7 +473,7 @@ class TagsController < ApplicationController
end
rename_tag_name!(locale, tag, name) if name_changed
alias_names << old_name if name_changed
alias_names << old_name if name_changed && old_name.present?
alias_names.delete(name)
update_aliases!(locale, tag, alias_names)
@@ -772,6 +772,7 @@ class TagsController < ApplicationController
script_code: locale.script_code,
name:,
primary_flg: true)
tag.association(:tag_names).reset
end
return
end
@@ -786,6 +787,9 @@ class TagsController < ApplicationController
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
end
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
current_tag_name.association(:wiki_page).reset
current_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
promoted_tag_name.update!(tag:, canonical_id: nil, primary_flg: true)
@@ -797,7 +801,6 @@ class TagsController < ApplicationController
alias_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
end
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
tag.update!(tag_name_id: promoted_tag_name.id)
current_tag_name.association(:wiki_page).reset
current_tag_name.association(:tag).reset
@@ -815,7 +818,9 @@ class TagsController < ApplicationController
affected_tags = [tag]
primary_tag_name = tag.tag_name(locale.language_code)
primary_tag_name = TagName.find_by!(tag:,
language_code: locale.language_code,
primary_flg: true)
current_aliases = tag.tag_names.where(language_code: locale.language_code,
primary_flg: false).to_a
+5 -1
ファイルの表示
@@ -94,7 +94,11 @@ class WikiPagesController < ApplicationController
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
tag_name = TagName.find_or_create_by!(name: title)
tag_name = TagName.find_or_create_by!(language_code: 'ja', name: title) do |name|
name.script_code = 'Jpan'
name.primary_flg = true
name.auto_generated = false
end
page =
Wiki::Commit.create_content!(
+23 -1
ファイルの表示
@@ -64,6 +64,7 @@ class Tag < ApplicationRecord
validates :category, presence: true, inclusion: { in: Tag.categories.keys }
validate :category_must_be_deerjikist_with_deerjikists
validate :tag_names_must_be_valid
CATEGORY_PREFIXES = {
'general:' => :general,
@@ -77,10 +78,22 @@ class Tag < ApplicationRecord
'mtr:' => :material,
'meta:' => :meta }.freeze
def tag_name(language_code) = tag_names.find_by(language_code:, primary_flg: true)
SYSTEM_TAG_NAMES = ['タグ希望', 'bot操作', 'ニジラー情報不詳', '動画', 'ニコニコ', 'YouTube'].freeze
def tag_name language_code
if tag_names.loaded?
tag_names.find { _1.language_code == language_code && _1.primary_flg }
else
tag_names.find_by(language_code:, primary_flg: true)
end
end
def name(language_code) = tag_name(language_code)&.name
def wiki_page = tag_name('ja')&.wiki_page
def system?
tag_name('ja')&.name.in?(SYSTEM_TAG_NAMES)
end
def deprecated? = deprecated_at?
def has_wiki = wiki_page.present?
@@ -232,6 +245,7 @@ class Tag < ApplicationRecord
tag = Tag.create!(tag_name_id: tn.id, category:)
tn.update!(tag:)
tag.association(:tag_names).reset
tag
rescue ActiveRecord::RecordNotUnique
@@ -307,6 +321,14 @@ class Tag < ApplicationRecord
private
def tag_names_must_be_valid
tag_names.each do |tag_name|
next if tag_name.valid?
tag_name.errors[:name].each { errors.add :name, _1 }
end
end
def category_must_be_deerjikist_with_deerjikists
if !(deerjikist?) && deerjikists.exists?
errors.add :category, 'ニジラーと紐づいてゐるタグはニジラー・カテゴリである必要があります.'
+1 -1
ファイルの表示
@@ -91,7 +91,7 @@ module PostRepr
post
.post_tags
.reject { _1.tag.deprecated? }
.sort_by { _1.tag.name(language_code) }
.sort_by { TagRepr.name_for(_1.tag, language_code) }
.map { |post_tag|
TagRepr.inline(post_tag.tag, language_code:).merge(
'children' => [],
+6 -2
ファイルの表示
@@ -8,14 +8,18 @@ module TagRepr
module_function
def base tag, language_code: 'ja'
tag.as_json(BASE).merge(name: tag.name(language_code),
tag.as_json(BASE).merge(name: name_for(tag, language_code),
aliases: tag.snapshot_aliases(language_code),
parents: tag.parents.map { inline(_1, language_code:) })
end
def inline tag, language_code: 'ja'
tag.as_json(BASE).merge(name: tag.name(language_code), aliases: [], parents: [])
tag.as_json(BASE).merge(name: name_for(tag, language_code), aliases: [], parents: [])
end
def many(tags, language_code: 'ja') = tags.map { |tag| base(tag, language_code:) }
def name_for tag, language_code
tag.name(language_code) || (tag.system? ? tag.name('ja') : nil)
end
end
+1 -1
ファイルの表示
@@ -463,7 +463,7 @@ class PostImportPreviewer
TagName.canonicalise(locale, name.sub(/\[.*\]\z/, '')).first
}
existing = parsed.filter_map { known_tags[_1] }
deprecated = existing.select(&:deprecated?).map(&:name)
deprecated = existing.select(&:deprecated?).map { _1.name(locale.language_code) }
errors[:tags] = ["廃止済みタグがあります: #{ deprecated.join(' ') }"] if deprecated.present?
rescue Tag::SectionLiteralParseError
errors[:tags] = ['タグ区間の記法が不正です.']
+8 -7
ファイルの表示
@@ -15,23 +15,24 @@ class TagVersionRecorder < VersionRecorder
def snapshot_attributes
names = snapshot_names
japanese_names = names.select { _1[:language_code] == 'ja' }
japanese_names = names.select { _1['language_code'] == 'ja' }
compatibility_names = japanese_names.presence || names
{ name: compatibility_names.find { _1[:primary_flg] }[:name],
{ name: compatibility_names.find { _1['primary_flg'] }['name'],
category: @record.category,
deprecated_at: @record.deprecated_at,
aliases: compatibility_names.reject { _1[:primary_flg] }.map { _1[:name] }.join(' '),
aliases: compatibility_names.reject { _1['primary_flg'] }.map { _1['name'] }.join(' '),
names:,
parent_tag_ids: @record.snapshot_parent_tag_ids.join(' ') }
end
def snapshot_names
@record.tag_names.order(:language_code, primary_flg: :desc).order(:name).map { |tag_name|
{ language_code: tag_name.language_code,
name: tag_name.name,
script_code: tag_name.script_code,
primary_flg: tag_name.primary_flg }
{ 'language_code' => tag_name.language_code,
'name' => tag_name.name,
'script_code' => tag_name.script_code,
'primary_flg' => tag_name.primary_flg,
'auto_generated' => tag_name.auto_generated }
}
end
end