このコミットが含まれているのは:
@@ -14,7 +14,11 @@ class ExternalTag < ApplicationRecord
|
||||
|
||||
has_many :linked_tags, through: :nico_tag_relations, source: :tag
|
||||
|
||||
def snapshot_linked_tag_names
|
||||
linked_tags.joins(:tag_name).order('tag_names.name').pluck('tag_names.name')
|
||||
def snapshot_linked_tag_names language_code = 'ja'
|
||||
linked_tags
|
||||
.joins(:tag_names)
|
||||
.where(tag_names: { language_code:, primary_flg: true })
|
||||
.order('tag_names.name')
|
||||
.pluck('tag_names.name')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Language < ApplicationRecord
|
||||
has_many :languages, class_name: 'Locale', foreign_key: :language_code
|
||||
has_many :locales, foreign_key: :language_code, primary_key: :code
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class Locale < ApplicationRecord
|
||||
Tag.where.not(id: tag_ids).find_each do
|
||||
TagName.create!(tag_id: _1.id,
|
||||
language_code:,
|
||||
name: TagName.generate_name!(self, _1, _1.name(language_code)),
|
||||
name: TagName.generate_name(self, _1, _1.name('ja')),
|
||||
script_code:,
|
||||
primary_flg: true,
|
||||
# TODO: 公証実装したら書く.
|
||||
|
||||
@@ -126,13 +126,14 @@ class Post < ApplicationRecord
|
||||
super(options).merge(thumbnail: nil)
|
||||
end
|
||||
|
||||
def snapshot_tag_names
|
||||
def snapshot_tag_names language_code = 'ja'
|
||||
post_tags
|
||||
.joins(tag: :tag_name)
|
||||
.includes(:sections, tag: :tag_name)
|
||||
.joins(tag: :tag_names)
|
||||
.where(tag_names: { language_code:, primary_flg: true })
|
||||
.includes(:sections, tag: :tag_names)
|
||||
.order('tag_names.name')
|
||||
.map do |post_tag|
|
||||
name = post_tag.tag.tag_name.name
|
||||
name = post_tag.tag.name(language_code)
|
||||
sections = post_tag.sections.sort_by(&:begin_ms)
|
||||
|
||||
next name if sections.empty?
|
||||
@@ -152,16 +153,17 @@ class Post < ApplicationRecord
|
||||
"#{ tag.fetch('name') }#{ sections.join }"
|
||||
end
|
||||
|
||||
def snapshot_tags_json
|
||||
def snapshot_tags_json language_code = 'ja'
|
||||
tag_snapshots =
|
||||
post_tags
|
||||
.joins(tag: :tag_name)
|
||||
.includes(:sections, tag: :tag_name)
|
||||
.joins(tag: :tag_names)
|
||||
.where(tag_names: { language_code:, primary_flg: true })
|
||||
.includes(:sections, tag: :tag_names)
|
||||
.order('tags.id')
|
||||
.map { |pt|
|
||||
{ 'tag_id' => pt.tag.id,
|
||||
'version_no' => pt.tag.version_no,
|
||||
'name' => pt.tag.name,
|
||||
'name' => pt.tag.name(language_code),
|
||||
'category' => pt.tag.category,
|
||||
'sections' => pt.sections.sort_by(&:begin_ms).map {
|
||||
{ 'begin_ms' => _1.begin_ms, 'end_ms' => _1.end_ms }
|
||||
|
||||
@@ -79,7 +79,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
def tag_name(language_code) = tag_names.find_by(language_code:, primary_flg: true)
|
||||
def name(language_code) = tag_name(language_code)&.name
|
||||
def wiki_page = WikiPage.find_by(tag_name_id: id)
|
||||
def wiki_page = tag_name('ja')&.wiki_page
|
||||
|
||||
def deprecated? = deprecated_at?
|
||||
|
||||
@@ -132,7 +132,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
find_or_create_by_tag_name!(locale, name, category: (cat || :general)).tap do |tag|
|
||||
if deny_deprecated && tag.deprecated?
|
||||
raise DeprecatedTagNormalisationError, [tag.name]
|
||||
raise DeprecatedTagNormalisationError, [tag.name(locale.language_code)]
|
||||
end
|
||||
|
||||
tag.update!(category: cat) if cat && tag.category != cat
|
||||
@@ -262,7 +262,7 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
source_tag_name = source_tag.tag_name
|
||||
source_tag_name = source_tag.tag_name('ja')
|
||||
|
||||
if source_tag_name.wiki_page.present?
|
||||
raise ActiveRecord::RecordInvalid.new(source_tag_name)
|
||||
@@ -291,7 +291,9 @@ class Tag < ApplicationRecord
|
||||
target_tag.reload
|
||||
end
|
||||
|
||||
def snapshot_aliases(language_code) = tag_name(language_code).aliases.order(:name).pluck(:name)
|
||||
def snapshot_aliases(language_code)
|
||||
tag_names.where(language_code:, primary_flg: false).order(:name).pluck(:name)
|
||||
end
|
||||
|
||||
def snapshot_parent_tag_ids = parents.order(:id).pluck(:id)
|
||||
|
||||
|
||||
@@ -14,9 +14,6 @@ class TagName < ApplicationRecord
|
||||
|
||||
def primary? = primary_flg
|
||||
|
||||
def canonical = TagName.find_by(language_code:, tag_id:, primary_flg: true)
|
||||
def aliases = TagName.where(language_code:, tag_id:, primary_flg: false)
|
||||
|
||||
def self.canonicalise locale, names
|
||||
names = Array(names).map { |n| n.to_s.strip }.reject(&:blank?)
|
||||
return [] if names.blank?
|
||||
@@ -24,17 +21,18 @@ class TagName < ApplicationRecord
|
||||
tns = TagName.where(language_code: locale.language_code, name: names).index_by(&:name)
|
||||
|
||||
names.map { |name|
|
||||
if !(tns[name]) || tns[name].primary?
|
||||
tag_name = tns[name]
|
||||
if !tag_name || tag_name.primary?
|
||||
name
|
||||
else
|
||||
TagName.find_by(language_code: locale.language_code,
|
||||
tag_id: tns[name].tag_id,
|
||||
primary_flg: true).name
|
||||
tag_id: tag_name.tag_id,
|
||||
primary_flg: true)&.name || name
|
||||
end
|
||||
}.uniq
|
||||
end
|
||||
|
||||
def self.generate_name! locale, tag, name
|
||||
def self.generate_name locale, tag, name
|
||||
# TODO: 言語ごとの自動命名ロジック完成したら書く.
|
||||
|
||||
"Tag_##{ tag.id }"
|
||||
|
||||
@@ -36,6 +36,7 @@ class TagNameSanitisationRule < ApplicationRecord
|
||||
if existing_tag
|
||||
Tag.merge_tags!(existing_tag, source_tag) if tn.tag
|
||||
elsif source_tag
|
||||
tn.update_columns(tag_id: nil, updated_at: Time.current)
|
||||
source_tag.update_columns(tag_name_id: existing_tn.id, updated_at: Time.current)
|
||||
existing_tn.update_columns(tag_id: source_tag.id, updated_at: Time.current)
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする