このコミットが含まれているのは:
@@ -7,7 +7,7 @@ class DeerjikistsController < ApplicationController
|
|||||||
|
|
||||||
deerjikist = Deerjikist
|
deerjikist = Deerjikist
|
||||||
.joins(:tag)
|
.joins(:tag)
|
||||||
.includes(tag: :tag_name)
|
.includes(tag: :tag_names)
|
||||||
.find_by(platform:, code:)
|
.find_by(platform:, code:)
|
||||||
if deerjikist
|
if deerjikist
|
||||||
render json: DeerjikistRepr.base(deerjikist)
|
render json: DeerjikistRepr.base(deerjikist)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class GekanatorPostsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
posts =
|
posts =
|
||||||
Post
|
Post
|
||||||
.preload(:post_similarities, tags: :tag_name)
|
.preload(:post_similarities, tags: :tag_names)
|
||||||
.with_attached_thumbnail
|
.with_attached_thumbnail
|
||||||
.order(Arel.sql(
|
.order(Arel.sql(
|
||||||
'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE, ' \
|
'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE, ' \
|
||||||
@@ -56,7 +56,7 @@ class GekanatorPostsController < ApplicationController
|
|||||||
def tag_json tag
|
def tag_json tag
|
||||||
{
|
{
|
||||||
id: tag.id,
|
id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name('ja'),
|
||||||
category: tag.category
|
category: tag.category
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ class GekanatorQuestionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_name)
|
.joins(:tag_names)
|
||||||
.where(category: categories.uniq)
|
.where(category: categories.uniq)
|
||||||
.where(tag_names: { name: names.uniq })
|
.where(tag_names: { language_code: 'ja', primary_flg: true, name: names.uniq })
|
||||||
.where.not(deprecated_at: nil)
|
.where.not(deprecated_at: nil)
|
||||||
.pluck('tags.category', 'tag_names.name')
|
.pluck('tags.category', 'tag_names.name')
|
||||||
.each_with_object({ }) do |(category, name), h|
|
.each_with_object({ }) do |(category, name), h|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class MaterialsController < ApplicationController
|
|||||||
q = Material.includes(:material_export_items,
|
q = Material.includes(:material_export_items,
|
||||||
thumbnail_attachment: :blob,
|
thumbnail_attachment: :blob,
|
||||||
file_attachment: :blob,
|
file_attachment: :blob,
|
||||||
tag: :tag_name)
|
tag: :tag_names)
|
||||||
q = q.where(tag_id: nil) if filters[:tag_state] == 'untagged'
|
q = q.where(tag_id: nil) if filters[:tag_state] == 'untagged'
|
||||||
q = q.where.not(tag_id: nil) if filters[:tag_state] == 'tagged'
|
q = q.where.not(tag_id: nil) if filters[:tag_state] == 'tagged'
|
||||||
q = apply_material_tag_filter(q, filters, tag_graph)
|
q = apply_material_tag_filter(q, filters, tag_graph)
|
||||||
@@ -63,7 +63,7 @@ class MaterialsController < ApplicationController
|
|||||||
.find_by(id: params[:id])
|
.find_by(id: params[:id])
|
||||||
return head :not_found unless material
|
return head :not_found unless material
|
||||||
|
|
||||||
wiki_page_body = material.tag&.tag_name&.wiki_page&.current_revision&.body
|
wiki_page_body = material.tag&.tag_name('ja')&.wiki_page&.current_revision&.body
|
||||||
|
|
||||||
render json: MaterialRepr.base(material, host: request.base_url).merge(wiki_page_body:)
|
render json: MaterialRepr.base(material, host: request.base_url).merge(wiki_page_body:)
|
||||||
end
|
end
|
||||||
@@ -96,7 +96,8 @@ class MaterialsController < ApplicationController
|
|||||||
updated_by_user: current_user)
|
updated_by_user: current_user)
|
||||||
material.file.attach(uploaded_blob) if uploaded_blob
|
material.file.attach(uploaded_blob) if uploaded_blob
|
||||||
material.save!
|
material.save!
|
||||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
upsert_export_paths!(material)
|
upsert_export_paths!(material)
|
||||||
MaterialVersionRecorder.record!(material:, event_type: :create,
|
MaterialVersionRecorder.record!(material:, event_type: :create,
|
||||||
created_by_user: current_user)
|
created_by_user: current_user)
|
||||||
@@ -148,7 +149,8 @@ class MaterialsController < ApplicationController
|
|||||||
material.file.detach
|
material.file.detach
|
||||||
end
|
end
|
||||||
material.save!
|
material.save!
|
||||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
upsert_export_paths!(material)
|
upsert_export_paths!(material)
|
||||||
MaterialVersionRecorder.record!(material:, event_type: :update,
|
MaterialVersionRecorder.record!(material:, event_type: :update,
|
||||||
created_by_user: current_user)
|
created_by_user: current_user)
|
||||||
@@ -254,7 +256,12 @@ class MaterialsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def material_index_join_tag_name q
|
def material_index_join_tag_name q
|
||||||
q.left_joins(tag: :tag_name)
|
q.left_joins(:tag).joins(<<~SQL.squish)
|
||||||
|
LEFT JOIN tag_names
|
||||||
|
ON tag_names.tag_id = tags.id
|
||||||
|
AND tag_names.language_code = 'ja'
|
||||||
|
AND tag_names.primary_flg = TRUE
|
||||||
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
def material_index_join_file_blob q
|
def material_index_join_file_blob q
|
||||||
@@ -270,9 +277,11 @@ class MaterialsController < ApplicationController
|
|||||||
|
|
||||||
def apply_material_query q, term
|
def apply_material_query q, term
|
||||||
like = "%#{ ActiveRecord::Base.sanitize_sql_like(term) }%"
|
like = "%#{ ActiveRecord::Base.sanitize_sql_like(term) }%"
|
||||||
q.where('tag_names.name LIKE :q OR materials.url LIKE :q OR ' \
|
q.where(<<~SQL.squish, q: like)
|
||||||
'material_file_blobs.filename LIKE :q',
|
tag_names.name LIKE :q
|
||||||
q: like)
|
OR materials.url LIKE :q
|
||||||
|
OR material_file_blobs.filename LIKE :q
|
||||||
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_material_media_kind q, media_kind
|
def apply_material_media_kind q, media_kind
|
||||||
@@ -324,8 +333,9 @@ class MaterialsController < ApplicationController
|
|||||||
end
|
end
|
||||||
tags_by_id =
|
tags_by_id =
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_name)
|
.joins(:tag_names)
|
||||||
.where(id: scope_tag_ids)
|
.where(id: scope_tag_ids,
|
||||||
|
tag_names: { language_code: 'ja', primary_flg: true })
|
||||||
.pluck('tags.id', 'tag_names.name', 'tags.category', 'tags.deprecated_at')
|
.pluck('tags.id', 'tag_names.name', 'tags.category', 'tags.deprecated_at')
|
||||||
.each_with_object({ }) do |(id, name, category, deprecated_at), hash|
|
.each_with_object({ }) do |(id, name, category, deprecated_at), hash|
|
||||||
hash[id] = { id:, name:, category:, deprecated: deprecated_at.present? }
|
hash[id] = { id:, name:, category:, deprecated: deprecated_at.present? }
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class NicoTagsController < ApplicationController
|
|||||||
ExternalTag
|
ExternalTag
|
||||||
.joins("LEFT JOIN (#{ post_tag_max_sql }) post_tag_max " \
|
.joins("LEFT JOIN (#{ post_tag_max_sql }) post_tag_max " \
|
||||||
'ON post_tag_max.external_tag_id = external_tags.id')
|
'ON post_tag_max.external_tag_id = external_tags.id')
|
||||||
.includes(linked_tags: { tag_name: :wiki_page })
|
.includes(linked_tags: { tag_names: :wiki_page })
|
||||||
if name
|
if name
|
||||||
q = q.where(('external_tags.name LIKE ? ' +
|
q = q.where(('external_tags.name LIKE ? ' +
|
||||||
"OR CONCAT(external_tags.platform, ':', external_tags.name) LIKE ?"),
|
"OR CONCAT(external_tags.platform, ':', external_tags.name) LIKE ?"),
|
||||||
@@ -34,7 +34,8 @@ class NicoTagsController < ApplicationController
|
|||||||
if linked_tag
|
if linked_tag
|
||||||
linked_tag_ids =
|
linked_tag_ids =
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_name)
|
.joins(:tag_names)
|
||||||
|
.where(tag_names: { language_code: 'ja', primary_flg: true })
|
||||||
.where('tag_names.name LIKE ?', "%#{ linked_tag }%")
|
.where('tag_names.name LIKE ?', "%#{ linked_tag }%")
|
||||||
.pluck(:id)
|
.pluck(:id)
|
||||||
linked_nico_tag_ids = NicoTagRelation.where(tag_id: linked_tag_ids).pluck(:nico_tag_id)
|
linked_nico_tag_ids = NicoTagRelation.where(tag_id: linked_tag_ids).pluck(:nico_tag_id)
|
||||||
@@ -95,7 +96,10 @@ class NicoTagsController < ApplicationController
|
|||||||
with_tagme: false,
|
with_tagme: false,
|
||||||
with_no_deerjikist: false)
|
with_no_deerjikist: false)
|
||||||
|
|
||||||
TagVersioning.record_tag_snapshots!(linked_tags, created_by_user: current_user)
|
TagVersioning.record_tag_snapshots!(
|
||||||
|
linked_tags,
|
||||||
|
created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
|
|
||||||
tag.linked_tags = linked_tags
|
tag.linked_tags = linked_tags
|
||||||
tag.save!
|
tag.save!
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class PostsController < ApplicationController
|
|||||||
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
|
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
|
||||||
.preload(:external_tags, :uploaded_user, :parents, :children,
|
.preload(:external_tags, :uploaded_user, :parents, :children,
|
||||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||||
{ tag_name: :wiki_page }] }])
|
{ tag_names: :wiki_page }] }])
|
||||||
.with_attached_thumbnail
|
.with_attached_thumbnail
|
||||||
|
|
||||||
q = q.where('posts.url LIKE ?', "%#{ url }%") if url
|
q = q.where('posts.url LIKE ?', "%#{ url }%") if url
|
||||||
@@ -110,7 +110,7 @@ class PostsController < ApplicationController
|
|||||||
filtered_posts(locale)
|
filtered_posts(locale)
|
||||||
.preload(:uploaded_user, :parents, :children,
|
.preload(:uploaded_user, :parents, :children,
|
||||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||||
{ tag_name: :wiki_page }] }])
|
{ tag_names: :wiki_page }] }])
|
||||||
.with_attached_thumbnail
|
.with_attached_thumbnail
|
||||||
.order('RAND()')
|
.order('RAND()')
|
||||||
.first
|
.first
|
||||||
@@ -195,7 +195,7 @@ class PostsController < ApplicationController
|
|||||||
Post
|
Post
|
||||||
.includes(:uploaded_user, :parents, :children,
|
.includes(:uploaded_user, :parents, :children,
|
||||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||||
{ tag_name: :wiki_page }] }])
|
{ tag_names: :wiki_page }] }])
|
||||||
.with_attached_thumbnail
|
.with_attached_thumbnail
|
||||||
.find_by(id: params[:id])
|
.find_by(id: params[:id])
|
||||||
return head :not_found unless post
|
return head :not_found unless post
|
||||||
@@ -341,7 +341,7 @@ class PostsController < ApplicationController
|
|||||||
base_version = post.post_versions.find_by!(version_no: base_version_no)
|
base_version = post.post_versions.find_by!(version_no: base_version_no)
|
||||||
|
|
||||||
base_snapshot = post_snapshot_from_version(base_version)
|
base_snapshot = post_snapshot_from_version(base_version)
|
||||||
current_snapshot = post_snapshot_from_record(post)
|
current_snapshot = post_snapshot_from_record(post, locale)
|
||||||
end
|
end
|
||||||
incoming_snapshot = post_incoming_snapshot(locale:,
|
incoming_snapshot = post_incoming_snapshot(locale:,
|
||||||
title:,
|
title:,
|
||||||
@@ -418,11 +418,11 @@ class PostsController < ApplicationController
|
|||||||
|
|
||||||
if match_type == 'any'
|
if match_type == 'any'
|
||||||
literals.reduce(Post.none) do |posts, literal|
|
literals.reduce(Post.none) do |posts, literal|
|
||||||
posts.or(tag_literal_relation(literal[:name], negative: literal[:negative]))
|
posts.or(tag_literal_relation(locale, literal[:name], negative: literal[:negative]))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
literals.reduce(Post.all) do |posts, literal|
|
literals.reduce(Post.all) do |posts, literal|
|
||||||
ids = tagged_post_ids_for(literal[:name])
|
ids = tagged_post_ids_for(locale, literal[:name])
|
||||||
if literal[:negative]
|
if literal[:negative]
|
||||||
posts.where.not(id: ids)
|
posts.where.not(id: ids)
|
||||||
else
|
else
|
||||||
@@ -432,8 +432,8 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_literal_relation name, negative:
|
def tag_literal_relation locale, name, negative:
|
||||||
ids = tagged_post_ids_for(name)
|
ids = tagged_post_ids_for(locale, name)
|
||||||
if negative
|
if negative
|
||||||
Post.where.not(id: ids)
|
Post.where.not(id: ids)
|
||||||
else
|
else
|
||||||
@@ -441,11 +441,11 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tagged_post_ids_for(name)
|
def tagged_post_ids_for locale, name
|
||||||
posts_by_internal_tags =
|
posts_by_internal_tags =
|
||||||
Post
|
Post
|
||||||
.joins(tags: :tag_name)
|
.joins(tags: :tag_names)
|
||||||
.where(tag_names: { name: })
|
.where(tag_names: { language_code: locale.language_code, name: })
|
||||||
.select(:id)
|
.select(:id)
|
||||||
|
|
||||||
posts_by_external_tags =
|
posts_by_external_tags =
|
||||||
@@ -688,24 +688,25 @@ class PostsController < ApplicationController
|
|||||||
.sort
|
.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_snapshot_from_record post
|
def post_snapshot_from_record post, locale
|
||||||
{ title: post.title,
|
{ title: post.title,
|
||||||
video_ms: post.video_ms,
|
video_ms: post.video_ms,
|
||||||
original_created_from: snapshot_time(post.original_created_from),
|
original_created_from: snapshot_time(post.original_created_from),
|
||||||
original_created_before: snapshot_time(post.original_created_before),
|
original_created_before: snapshot_time(post.original_created_before),
|
||||||
tag_names: editable_tag_names_from_post(post),
|
tag_names: editable_tag_names_from_post(post, locale.language_code),
|
||||||
parent_post_ids: post.parent_posts.order(:id).pluck(:id) }
|
parent_post_ids: post.parent_posts.order(:id).pluck(:id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def editable_tag_names_from_post post
|
def editable_tag_names_from_post post, language_code
|
||||||
post
|
post
|
||||||
.post_tags
|
.post_tags
|
||||||
.joins(tag: :tag_name)
|
.joins(tag: :tag_names)
|
||||||
.merge(Tag.where(deprecated_at: nil))
|
.merge(Tag.where(deprecated_at: nil))
|
||||||
.includes(:sections, tag: :tag_name)
|
.where(tag_names: { language_code:, primary_flg: true })
|
||||||
|
.includes(:sections, tag: :tag_names)
|
||||||
.order('tag_names.name')
|
.order('tag_names.name')
|
||||||
.map do |post_tag|
|
.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)
|
sections = post_tag.sections.sort_by(&:begin_ms)
|
||||||
|
|
||||||
next name if sections.empty?
|
next name if sections.empty?
|
||||||
@@ -732,7 +733,7 @@ class PostsController < ApplicationController
|
|||||||
original_created_from: snapshot_time(original_created_from),
|
original_created_from: snapshot_time(original_created_from),
|
||||||
original_created_before: snapshot_time(original_created_before),
|
original_created_before: snapshot_time(original_created_before),
|
||||||
tag_names: tags.uniq(&:id).map { |tag|
|
tag_names: tags.uniq(&:id).map { |tag|
|
||||||
"#{ tag.name }#{ sections[tag.id].to_a.map { section_literal(_1) }.join }"
|
"#{ tag.name(locale.language_code) }#{ sections[tag.id].to_a.map { section_literal(_1) }.join }"
|
||||||
}.sort,
|
}.sort,
|
||||||
parent_post_ids: parent_post_ids.sort }
|
parent_post_ids: parent_post_ids.sort }
|
||||||
end
|
end
|
||||||
@@ -868,7 +869,8 @@ class PostsController < ApplicationController
|
|||||||
with_tagme: false,
|
with_tagme: false,
|
||||||
deny_deprecated: true,
|
deny_deprecated: true,
|
||||||
with_sections: true) => { tags:, sections: }
|
with_sections: true) => { tags:, sections: }
|
||||||
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user)
|
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
|
|
||||||
tags = Tag.expand_parent_tags(tags).reject(&:deprecated?)
|
tags = Tag.expand_parent_tags(tags).reject(&:deprecated?)
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class TagVersionsController < ApplicationController
|
|||||||
|
|
||||||
tags_by_id =
|
tags_by_id =
|
||||||
Tag
|
Tag
|
||||||
.includes(:tag_name, :materials, { tag_name: :wiki_page })
|
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||||
.where(id: all_parent_tag_ids)
|
.where(id: all_parent_tag_ids)
|
||||||
.index_by(&:id)
|
.index_by(&:id)
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ class TagsController < ApplicationController
|
|||||||
Tag
|
Tag
|
||||||
.joins(:tag_names)
|
.joins(:tag_names)
|
||||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||||
.where(tag_names: { language_code: locale.language.code, primary_flg: true },
|
.where(tag_names: { language_code: locale.language_code, primary_flg: true },
|
||||||
id: tag_ids)
|
id: tag_ids)
|
||||||
.index_by(&:id)
|
.index_by(&:id)
|
||||||
external_tags_by_id =
|
external_tags_by_id =
|
||||||
@@ -186,7 +186,7 @@ class TagsController < ApplicationController
|
|||||||
|
|
||||||
render json: { tags: rows.map { |row|
|
render json: { tags: rows.map { |row|
|
||||||
if row['source'] == 'tag'
|
if row['source'] == 'tag'
|
||||||
TagRepr.base(tags_by_id.fetch(row['id']))
|
TagRepr.base(tags_by_id.fetch(row['id']), language_code: locale.language_code)
|
||||||
else
|
else
|
||||||
external_tag_json(external_tags_by_id.fetch(row['id']))
|
external_tag_json(external_tags_by_id.fetch(row['id']))
|
||||||
end
|
end
|
||||||
@@ -223,15 +223,15 @@ class TagsController < ApplicationController
|
|||||||
|
|
||||||
alias_rows =
|
alias_rows =
|
||||||
TagName
|
TagName
|
||||||
.where(language_code: locale.language_code, primary_code: false)
|
.where(language_code: locale.language_code, primary_flg: false)
|
||||||
.where('name LIKE ?', prefix)
|
.where('name LIKE ?', prefix)
|
||||||
.pluck(:tag_id, :name)
|
.pluck(:tag_id, :name)
|
||||||
|
|
||||||
matched_alias_by_tag_name_id = { }
|
matched_alias_by_tag_id = { }
|
||||||
tag_ids = []
|
tag_ids = []
|
||||||
alias_rows.each do |tag_id, alias_name|
|
alias_rows.each do |tag_id, alias_name|
|
||||||
tag_ids << tag_id
|
tag_ids << tag_id
|
||||||
matched_alias_by_tag_name_id[tag_id] ||= alias_name
|
matched_alias_by_tag_id[tag_id] ||= alias_name
|
||||||
end
|
end
|
||||||
|
|
||||||
base =
|
base =
|
||||||
@@ -251,7 +251,8 @@ class TagsController < ApplicationController
|
|||||||
.order(Arel.sql('tags.post_count DESC, tag_names.name'))
|
.order(Arel.sql('tags.post_count DESC, tag_names.name'))
|
||||||
.limit(20)
|
.limit(20)
|
||||||
.map { |tag|
|
.map { |tag|
|
||||||
TagRepr.base(tag).merge(matched_alias: matched_alias_by_tag_name_id[tag.tag_name_id])
|
TagRepr.base(tag, language_code: locale.language_code)
|
||||||
|
.merge(matched_alias: matched_alias_by_tag_id[tag.id])
|
||||||
}
|
}
|
||||||
|
|
||||||
return render json: internal_rows unless with_nico
|
return render json: internal_rows unless with_nico
|
||||||
@@ -267,8 +268,8 @@ class TagsController < ApplicationController
|
|||||||
.map { external_tag_json(_1) }
|
.map { external_tag_json(_1) }
|
||||||
|
|
||||||
rows =
|
rows =
|
||||||
(internal_rows + external_rows)
|
(internal_rows + external_rows)
|
||||||
.sort_by { |row| [-row['post_count'], row['name']] }
|
.sort_by { |row| [-row['post_count'], row['name'] || row[:name]] }
|
||||||
.first(20)
|
.first(20)
|
||||||
|
|
||||||
render json: rows
|
render json: rows
|
||||||
@@ -283,7 +284,7 @@ class TagsController < ApplicationController
|
|||||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||||
.find_by(id: params[:id],
|
.find_by(id: params[:id],
|
||||||
tag_names: { language_code: locale.language_code, primary_flg: true })
|
tag_names: { language_code: locale.language_code, primary_flg: true })
|
||||||
return render json: TagRepr.base(tag) if tag
|
return render json: TagRepr.base(tag, language_code: locale.language_code) if tag
|
||||||
|
|
||||||
external_tag = ExternalTag.find_by(id: params[:id])
|
external_tag = ExternalTag.find_by(id: params[:id])
|
||||||
return render json: ExternalTagRepr.base(external_tag) if external_tag
|
return render json: ExternalTagRepr.base(external_tag) if external_tag
|
||||||
@@ -302,7 +303,7 @@ class TagsController < ApplicationController
|
|||||||
.joins(:tag_names)
|
.joins(:tag_names)
|
||||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||||
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
||||||
return render json: TagRepr.base(tag) if tag
|
return render json: TagRepr.base(tag, language_code: locale.language_code) if tag
|
||||||
|
|
||||||
platform, external_name = name.split(':', 2)
|
platform, external_name = name.split(':', 2)
|
||||||
return head :not_found unless external_name
|
return head :not_found unless external_name
|
||||||
@@ -323,7 +324,7 @@ class TagsController < ApplicationController
|
|||||||
tag_names: { language_code: locale.language_code, primary_flg: true })
|
tag_names: { language_code: locale.language_code, primary_flg: true })
|
||||||
return head :not_found unless tag
|
return head :not_found unless tag
|
||||||
|
|
||||||
render json: { tag: TagRepr.base(tag),
|
render json: { tag: TagRepr.base(tag, language_code: locale.language_code),
|
||||||
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -340,7 +341,7 @@ class TagsController < ApplicationController
|
|||||||
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
||||||
return head :not_found unless tag
|
return head :not_found unless tag
|
||||||
|
|
||||||
render json: { tag: TagRepr.base(tag),
|
render json: { tag: TagRepr.base(tag, language_code: locale.language_code),
|
||||||
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -348,6 +349,8 @@ class TagsController < ApplicationController
|
|||||||
return head :unauthorized unless current_user
|
return head :unauthorized unless current_user
|
||||||
return head :forbidden unless current_user.gte_member?
|
return head :forbidden unless current_user.gte_member?
|
||||||
|
|
||||||
|
locale = resolve_locale!
|
||||||
|
|
||||||
tag =
|
tag =
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_names)
|
.joins(:tag_names)
|
||||||
@@ -359,8 +362,6 @@ class TagsController < ApplicationController
|
|||||||
rows = normalise_deerjikist_rows(tag)
|
rows = normalise_deerjikist_rows(tag)
|
||||||
return if performed?
|
return if performed?
|
||||||
|
|
||||||
locale = resolve_locale!
|
|
||||||
|
|
||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
tag.lock!
|
tag.lock!
|
||||||
|
|
||||||
@@ -423,7 +424,7 @@ class TagsController < ApplicationController
|
|||||||
|
|
||||||
graph = build_with_depth_graph(material_filter)
|
graph = build_with_depth_graph(material_filter)
|
||||||
|
|
||||||
render json: build_tag_children(tag, graph:)
|
render json: build_tag_children(tag, graph:, language_code: locale.language_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_all
|
def update_all
|
||||||
@@ -452,11 +453,12 @@ class TagsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
|
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
|
|
||||||
old_name = tag.name
|
old_name = tag.name(locale.language_code)
|
||||||
name_changed = name != old_name
|
name_changed = name != old_name
|
||||||
wiki_page = tag.tag_name.wiki_page if name_changed
|
wiki_page = tag.tag_name(locale.language_code)&.wiki_page if name_changed
|
||||||
|
|
||||||
if tag.deprecated? == deprecated
|
if tag.deprecated? == deprecated
|
||||||
tag.update!(category:)
|
tag.update!(category:)
|
||||||
@@ -468,7 +470,7 @@ class TagsController < ApplicationController
|
|||||||
alias_names << old_name if name_changed
|
alias_names << old_name if name_changed
|
||||||
alias_names.delete(name)
|
alias_names.delete(name)
|
||||||
|
|
||||||
update_aliases!(tag, alias_names)
|
update_aliases!(locale, tag, alias_names)
|
||||||
update_parent_tags!(locale, tag, parent_names)
|
update_parent_tags!(locale, tag, parent_names)
|
||||||
|
|
||||||
tag.reload
|
tag.reload
|
||||||
@@ -477,11 +479,12 @@ class TagsController < ApplicationController
|
|||||||
tag,
|
tag,
|
||||||
event_type: :update,
|
event_type: :update,
|
||||||
created_by_user: current_user,
|
created_by_user: current_user,
|
||||||
|
language_code: locale.language_code,
|
||||||
name_changed:,
|
name_changed:,
|
||||||
wiki_page:)
|
wiki_page:)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: TagRepr.base(tag.reload)
|
render json: TagRepr.base(tag.reload, language_code: locale.language_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -504,13 +507,14 @@ class TagsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
|
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
|
|
||||||
old_name = tag.name
|
old_name = tag.name(locale.language_code)
|
||||||
name_changed = name.present? && name != old_name
|
name_changed = name.present? && name != old_name
|
||||||
wiki_page = tag.tag_name.wiki_page if name_changed
|
wiki_page = tag.tag_name(locale.language_code)&.wiki_page if name_changed
|
||||||
|
|
||||||
rename_tag_name!(tag, name) if name_changed
|
rename_tag_name!(locale, tag, name) if name_changed
|
||||||
tag.update!(category:) if category.present?
|
tag.update!(category:) if category.present?
|
||||||
if deprecated_given && tag.deprecated? != deprecated
|
if deprecated_given && tag.deprecated? != deprecated
|
||||||
tag.update!(deprecated_at: deprecated ? Time.current : nil)
|
tag.update!(deprecated_at: deprecated ? Time.current : nil)
|
||||||
@@ -522,11 +526,12 @@ class TagsController < ApplicationController
|
|||||||
tag,
|
tag,
|
||||||
event_type: :update,
|
event_type: :update,
|
||||||
created_by_user: current_user,
|
created_by_user: current_user,
|
||||||
|
language_code: locale.language_code,
|
||||||
name_changed:,
|
name_changed:,
|
||||||
wiki_page:)
|
wiki_page:)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: TagRepr.base(tag.reload)
|
render json: TagRepr.base(tag.reload, language_code: locale.language_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -693,29 +698,30 @@ class TagsController < ApplicationController
|
|||||||
children: [] }
|
children: [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_tag_children tag, graph: nil
|
def build_tag_children tag, graph: nil, language_code: 'ja'
|
||||||
material = tag.materials.first
|
material = tag.materials.first
|
||||||
tag_graph = graph && graph[:tags_by_id][tag.id]
|
tag_graph = graph && graph[:tags_by_id][tag.id]
|
||||||
material =
|
material =
|
||||||
nil if tag_graph && !with_depth_visible_tag?(tag_graph, graph[:material_filter])
|
nil if tag_graph && !with_depth_visible_tag?(tag_graph, graph[:material_filter])
|
||||||
|
|
||||||
children = tag.children.sort_by(&:name)
|
children = tag.children.sort_by { _1.name(language_code) }
|
||||||
if graph
|
if graph
|
||||||
children = children.filter { |child_tag| visible_subtree?(child_tag.id, graph) }
|
children = children.filter { |child_tag| visible_subtree?(child_tag.id, graph) }
|
||||||
end
|
end
|
||||||
|
|
||||||
TagRepr.base(tag).merge(
|
TagRepr.base(tag, language_code:).merge(
|
||||||
children: children.map { build_tag_children(_1, graph:) },
|
children: children.map { build_tag_children(_1, graph:, language_code:) },
|
||||||
has_material: tag_graph ? tag_graph[:has_material] : material.present?,
|
has_material: tag_graph ? tag_graph[:has_material] : material.present?,
|
||||||
material: material && MaterialRepr.base(material, host: request.base_url))
|
material: material && MaterialRepr.base(material, host: request.base_url))
|
||||||
end
|
end
|
||||||
|
|
||||||
def record_tag_version! tag, event_type:, created_by_user:, name_changed: false, wiki_page: nil
|
def record_tag_version! tag, event_type:, created_by_user:, language_code: 'ja',
|
||||||
TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
|
name_changed: false, wiki_page: nil
|
||||||
|
TagVersionRecorder.record!(tag:, event_type:, created_by_user:, language_code:)
|
||||||
|
|
||||||
return unless name_changed
|
return unless name_changed
|
||||||
|
|
||||||
wiki_page ||= tag.tag_name.wiki_page
|
wiki_page ||= tag.tag_name('ja')&.wiki_page
|
||||||
return unless wiki_page&.wiki_versions&.exists?
|
return unless wiki_page&.wiki_versions&.exists?
|
||||||
|
|
||||||
WikiVersionRecorder.record!(
|
WikiVersionRecorder.record!(
|
||||||
@@ -725,9 +731,13 @@ class TagsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_tag_rename locale, tag, name
|
def validate_tag_rename locale, tag, name
|
||||||
return true if name.blank? || name == tag.name
|
return true if name.blank? || name == tag.name(locale.language_code)
|
||||||
|
|
||||||
if tag.in?([Tag.tagme, Tag.bot, Tag.no_deerjikist, Tag.video, Tag.niconico])
|
system_tag_names = ['タグ希望', 'bot操作', 'ニジラー情報不詳', '動画', 'ニコニコ']
|
||||||
|
if TagName.exists?(tag_id: tag.id,
|
||||||
|
language_code: 'ja',
|
||||||
|
primary_flg: true,
|
||||||
|
name: system_tag_names)
|
||||||
render_unprocessable_entity 'システム・タグの名称は変更できません.', field: :name
|
render_unprocessable_entity 'システム・タグの名称は変更できません.', field: :name
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -746,7 +756,16 @@ class TagsController < ApplicationController
|
|||||||
target_tag_name = TagName.find_by(language_code: locale.language_code, name:)
|
target_tag_name = TagName.find_by(language_code: locale.language_code, name:)
|
||||||
|
|
||||||
unless target_tag_name
|
unless target_tag_name
|
||||||
current_tag_name.update!(name:)
|
if current_tag_name
|
||||||
|
current_tag_name.update!(name:)
|
||||||
|
else
|
||||||
|
current_tag_name = TagName.create!(
|
||||||
|
tag:,
|
||||||
|
language_code: locale.language_code,
|
||||||
|
script_code: locale.script_code,
|
||||||
|
name:,
|
||||||
|
primary_flg: true)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -754,68 +773,79 @@ class TagsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def promote_tag_alias! tag, current_tag_name:, promoted_tag_name:
|
def promote_tag_alias! tag, current_tag_name:, promoted_tag_name:
|
||||||
old_owner_tag = promoted_tag_name.canonical&.tag
|
old_owner_tag = promoted_tag_name.tag
|
||||||
|
|
||||||
if old_owner_tag && old_owner_tag != tag
|
if old_owner_tag && old_owner_tag != tag
|
||||||
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
|
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
promoted_tag_name.update!(canonical_id: nil, primary_flg: true)
|
current_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||||
|
promoted_tag_name.update!(tag:, canonical_id: nil, primary_flg: true)
|
||||||
|
|
||||||
TagName.where(tag:,
|
TagName.where(tag:,
|
||||||
language_code: current_tag_name.language.language_code,
|
language_code: current_tag_name.language_code,
|
||||||
primary_flg: false)
|
primary_flg: false)
|
||||||
.where.not(id: promoted_tag_name.id)
|
.where.not(id: promoted_tag_name.id)
|
||||||
.find_each do |alias_tag_name|
|
.find_each do |alias_tag_name|
|
||||||
alias_tag_name.update!(canonical_id: promoted_tag_name, primary_flg: false)
|
alias_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
|
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
|
||||||
tag.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(:wiki_page).reset
|
||||||
current_tag_name.association(:tag).reset
|
current_tag_name.association(:tag).reset
|
||||||
current_tag_name.reload.update!(canonical_id: promoted_tag_name, primary_flg: false)
|
current_tag_name.reload.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||||
|
|
||||||
return unless old_owner_tag && old_owner_tag != tag
|
return unless old_owner_tag && old_owner_tag != tag
|
||||||
|
|
||||||
record_tag_version!(old_owner_tag.reload, event_type: :update, created_by_user: current_user)
|
record_tag_version!(old_owner_tag.reload, event_type: :update,
|
||||||
|
created_by_user: current_user,
|
||||||
|
language_code: current_tag_name.language_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_aliases! tag, alias_names
|
def update_aliases! locale, tag, alias_names
|
||||||
alias_names = alias_names.uniq
|
alias_names = alias_names.uniq
|
||||||
|
|
||||||
affected_tags = [tag]
|
affected_tags = [tag]
|
||||||
|
|
||||||
current_aliases = tag.tag_name.aliases.to_a
|
primary_tag_name = tag.tag_name(locale.language_code)
|
||||||
|
current_aliases = tag.tag_names.where(language_code: locale.language_code,
|
||||||
|
primary_flg: false).to_a
|
||||||
|
|
||||||
current_aliases.each do |alias_tag_name|
|
current_aliases.each do |alias_tag_name|
|
||||||
next if alias_names.include?(alias_tag_name.name)
|
next if alias_names.include?(alias_tag_name.name)
|
||||||
|
|
||||||
affected_tags << alias_tag_name.canonical&.tag
|
affected_tags << alias_tag_name.tag
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_names.each do |alias_name|
|
alias_names.each do |alias_name|
|
||||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
alias_tag_name = TagName.find_by(language_code: locale.language_code, name: alias_name)
|
||||||
affected_tags << alias_tag_name.canonical&.tag
|
affected_tags << alias_tag_name&.tag
|
||||||
end
|
end
|
||||||
|
|
||||||
affected_tags.compact.uniq.each do |affected_tag|
|
affected_tags.compact.uniq.each do |affected_tag|
|
||||||
TagVersioning.ensure_snapshot!(affected_tag, created_by_user: current_user)
|
TagVersioning.ensure_snapshot!(affected_tag, created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
current_aliases.each do |alias_tag_name|
|
current_aliases.each do |alias_tag_name|
|
||||||
next if alias_names.include?(alias_tag_name.name)
|
next if alias_names.include?(alias_tag_name.name)
|
||||||
|
|
||||||
alias_tag_name.update!(canonical_id: nil)
|
alias_tag_name.update!(canonical_id: nil, tag_id: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_names.each do |alias_name|
|
alias_names.each do |alias_name|
|
||||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
alias_tag_name = TagName.find_or_initialize_by(
|
||||||
alias_tag_name.update!(canonical_id: tag.tag_name.id)
|
language_code: locale.language_code,
|
||||||
|
name: alias_name)
|
||||||
|
alias_tag_name.script_code = locale.script_code
|
||||||
|
alias_tag_name.update!(tag:, primary_flg: false, canonical_id: primary_tag_name.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
affected_tags.compact.uniq.each do |affected_tag|
|
affected_tags.compact.uniq.each do |affected_tag|
|
||||||
record_tag_version!(affected_tag, event_type: :update, created_by_user: current_user)
|
record_tag_version!(affected_tag, event_type: :update,
|
||||||
|
created_by_user: current_user,
|
||||||
|
language_code: locale.language_code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -899,8 +929,6 @@ class TagsController < ApplicationController
|
|||||||
conflicts = deerjikists.filter { |deerjikist| deerjikist.tag_id != tag.id }
|
conflicts = deerjikists.filter { |deerjikist| deerjikist.tag_id != tag.id }
|
||||||
return if conflicts.empty?
|
return if conflicts.empty?
|
||||||
|
|
||||||
locale = resolve_locale!
|
|
||||||
|
|
||||||
tag_names_by_id =
|
tag_names_by_id =
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_names)
|
.joins(:tag_names)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class TheatreSkipEventsController < ApplicationController
|
|||||||
events =
|
events =
|
||||||
TheatreSkipEvent
|
TheatreSkipEvent
|
||||||
.where(theatre_id: params[:theatre_id])
|
.where(theatre_id: params[:theatre_id])
|
||||||
.includes(:post, tags: :tag_name)
|
.includes(:post, tags: :tag_names)
|
||||||
.order(created_at: :desc)
|
.order(created_at: :desc)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ class TheatreSkipEventsController < ApplicationController
|
|||||||
{ id: event.id,
|
{ id: event.id,
|
||||||
theatre_id: event.theatre_id,
|
theatre_id: event.theatre_id,
|
||||||
post: { id: event.post.id, title: event.post.title, url: event.post.url },
|
post: { id: event.post.id, title: event.post.title, url: event.post.url },
|
||||||
tags: event.tags.map { |tag| { id: tag.id, name: tag.name } },
|
tags: event.tags.map { |tag| { id: tag.id, name: tag.name('ja') } },
|
||||||
programme_position: event.programme_position,
|
programme_position: event.programme_position,
|
||||||
created_at: event.created_at }
|
created_at: event.created_at }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ class ExternalTag < ApplicationRecord
|
|||||||
|
|
||||||
has_many :linked_tags, through: :nico_tag_relations, source: :tag
|
has_many :linked_tags, through: :nico_tag_relations, source: :tag
|
||||||
|
|
||||||
def snapshot_linked_tag_names
|
def snapshot_linked_tag_names language_code = 'ja'
|
||||||
linked_tags.joins(:tag_name).order('tag_names.name').pluck('tag_names.name')
|
linked_tags
|
||||||
|
.joins(:tag_names)
|
||||||
|
.where(tag_names: { language_code:, primary_flg: true })
|
||||||
|
.order('tag_names.name')
|
||||||
|
.pluck('tag_names.name')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
class Language < ApplicationRecord
|
class Language < ApplicationRecord
|
||||||
has_many :languages, class_name: 'Locale', foreign_key: :language_code
|
has_many :locales, foreign_key: :language_code, primary_key: :code
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Locale < ApplicationRecord
|
|||||||
Tag.where.not(id: tag_ids).find_each do
|
Tag.where.not(id: tag_ids).find_each do
|
||||||
TagName.create!(tag_id: _1.id,
|
TagName.create!(tag_id: _1.id,
|
||||||
language_code:,
|
language_code:,
|
||||||
name: TagName.generate_name!(self, _1, _1.name(language_code)),
|
name: TagName.generate_name(self, _1, _1.name('ja')),
|
||||||
script_code:,
|
script_code:,
|
||||||
primary_flg: true,
|
primary_flg: true,
|
||||||
# TODO: 公証実装したら書く.
|
# TODO: 公証実装したら書く.
|
||||||
|
|||||||
@@ -126,13 +126,14 @@ class Post < ApplicationRecord
|
|||||||
super(options).merge(thumbnail: nil)
|
super(options).merge(thumbnail: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def snapshot_tag_names
|
def snapshot_tag_names language_code = 'ja'
|
||||||
post_tags
|
post_tags
|
||||||
.joins(tag: :tag_name)
|
.joins(tag: :tag_names)
|
||||||
.includes(:sections, tag: :tag_name)
|
.where(tag_names: { language_code:, primary_flg: true })
|
||||||
|
.includes(:sections, tag: :tag_names)
|
||||||
.order('tag_names.name')
|
.order('tag_names.name')
|
||||||
.map do |post_tag|
|
.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)
|
sections = post_tag.sections.sort_by(&:begin_ms)
|
||||||
|
|
||||||
next name if sections.empty?
|
next name if sections.empty?
|
||||||
@@ -152,16 +153,17 @@ class Post < ApplicationRecord
|
|||||||
"#{ tag.fetch('name') }#{ sections.join }"
|
"#{ tag.fetch('name') }#{ sections.join }"
|
||||||
end
|
end
|
||||||
|
|
||||||
def snapshot_tags_json
|
def snapshot_tags_json language_code = 'ja'
|
||||||
tag_snapshots =
|
tag_snapshots =
|
||||||
post_tags
|
post_tags
|
||||||
.joins(tag: :tag_name)
|
.joins(tag: :tag_names)
|
||||||
.includes(:sections, tag: :tag_name)
|
.where(tag_names: { language_code:, primary_flg: true })
|
||||||
|
.includes(:sections, tag: :tag_names)
|
||||||
.order('tags.id')
|
.order('tags.id')
|
||||||
.map { |pt|
|
.map { |pt|
|
||||||
{ 'tag_id' => pt.tag.id,
|
{ 'tag_id' => pt.tag.id,
|
||||||
'version_no' => pt.tag.version_no,
|
'version_no' => pt.tag.version_no,
|
||||||
'name' => pt.tag.name,
|
'name' => pt.tag.name(language_code),
|
||||||
'category' => pt.tag.category,
|
'category' => pt.tag.category,
|
||||||
'sections' => pt.sections.sort_by(&:begin_ms).map {
|
'sections' => pt.sections.sort_by(&:begin_ms).map {
|
||||||
{ 'begin_ms' => _1.begin_ms, 'end_ms' => _1.end_ms }
|
{ '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 tag_name(language_code) = tag_names.find_by(language_code:, primary_flg: true)
|
||||||
def name(language_code) = tag_name(language_code)&.name
|
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?
|
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|
|
find_or_create_by_tag_name!(locale, name, category: (cat || :general)).tap do |tag|
|
||||||
if deny_deprecated && tag.deprecated?
|
if deny_deprecated && tag.deprecated?
|
||||||
raise DeprecatedTagNormalisationError, [tag.name]
|
raise DeprecatedTagNormalisationError, [tag.name(locale.language_code)]
|
||||||
end
|
end
|
||||||
|
|
||||||
tag.update!(category: cat) if cat && tag.category != cat
|
tag.update!(category: cat) if cat && tag.category != cat
|
||||||
@@ -262,7 +262,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
source_tag_name = source_tag.tag_name
|
source_tag_name = source_tag.tag_name('ja')
|
||||||
|
|
||||||
if source_tag_name.wiki_page.present?
|
if source_tag_name.wiki_page.present?
|
||||||
raise ActiveRecord::RecordInvalid.new(source_tag_name)
|
raise ActiveRecord::RecordInvalid.new(source_tag_name)
|
||||||
@@ -291,7 +291,9 @@ class Tag < ApplicationRecord
|
|||||||
target_tag.reload
|
target_tag.reload
|
||||||
end
|
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)
|
def snapshot_parent_tag_ids = parents.order(:id).pluck(:id)
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ class TagName < ApplicationRecord
|
|||||||
|
|
||||||
def primary? = primary_flg
|
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
|
def self.canonicalise locale, names
|
||||||
names = Array(names).map { |n| n.to_s.strip }.reject(&:blank?)
|
names = Array(names).map { |n| n.to_s.strip }.reject(&:blank?)
|
||||||
return [] if names.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)
|
tns = TagName.where(language_code: locale.language_code, name: names).index_by(&:name)
|
||||||
|
|
||||||
names.map { |name|
|
names.map { |name|
|
||||||
if !(tns[name]) || tns[name].primary?
|
tag_name = tns[name]
|
||||||
|
if !tag_name || tag_name.primary?
|
||||||
name
|
name
|
||||||
else
|
else
|
||||||
TagName.find_by(language_code: locale.language_code,
|
TagName.find_by(language_code: locale.language_code,
|
||||||
tag_id: tns[name].tag_id,
|
tag_id: tag_name.tag_id,
|
||||||
primary_flg: true).name
|
primary_flg: true)&.name || name
|
||||||
end
|
end
|
||||||
}.uniq
|
}.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_name! locale, tag, name
|
def self.generate_name locale, tag, name
|
||||||
# TODO: 言語ごとの自動命名ロジック完成したら書く.
|
# TODO: 言語ごとの自動命名ロジック完成したら書く.
|
||||||
|
|
||||||
"Tag_##{ tag.id }"
|
"Tag_##{ tag.id }"
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class TagNameSanitisationRule < ApplicationRecord
|
|||||||
if existing_tag
|
if existing_tag
|
||||||
Tag.merge_tags!(existing_tag, source_tag) if tn.tag
|
Tag.merge_tags!(existing_tag, source_tag) if tn.tag
|
||||||
elsif source_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)
|
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)
|
existing_tn.update_columns(tag_id: source_tag.id, updated_at: Time.current)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ module DeerjikistRepr
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def base deerjikist
|
def base deerjikist
|
||||||
deerjikist.as_json(BASE)
|
deerjikist.as_json(BASE).merge(
|
||||||
|
tag: deerjikist.tag && TagRepr.base(deerjikist.tag, language_code: 'ja'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def many deerjikists
|
def many deerjikists
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ module MaterialRepr
|
|||||||
|
|
||||||
def base material, host:
|
def base material, host:
|
||||||
material.as_json(BASE).merge(
|
material.as_json(BASE).merge(
|
||||||
|
tag: material.tag && TagRepr.base(material.tag, language_code: 'ja'),
|
||||||
file: if material.file.attached?
|
file: if material.file.attached?
|
||||||
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
||||||
material.file, host:)
|
material.file, host:)
|
||||||
@@ -80,7 +81,7 @@ module MaterialRepr
|
|||||||
end
|
end
|
||||||
|
|
||||||
def thumbnail_fallback_text material
|
def thumbnail_fallback_text material
|
||||||
material.tag&.name || material.created_at&.strftime('%Y-%m-%d')
|
material.tag&.name('ja') || material.created_at&.strftime('%Y-%m-%d')
|
||||||
end
|
end
|
||||||
|
|
||||||
def thumbnail_fallback_kind material
|
def thumbnail_fallback_kind material
|
||||||
@@ -102,7 +103,7 @@ module MaterialRepr
|
|||||||
return nil unless tag
|
return nil unless tag
|
||||||
|
|
||||||
{ id: tag.id,
|
{ id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name('ja'),
|
||||||
category: tag.category,
|
category: tag.category,
|
||||||
deprecated_at: tag.deprecated_at }
|
deprecated_at: tag.deprecated_at }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ module PostRepr
|
|||||||
post
|
post
|
||||||
.post_tags
|
.post_tags
|
||||||
.reject { _1.tag.deprecated? }
|
.reject { _1.tag.deprecated? }
|
||||||
.sort_by { _1.tag.name }
|
.sort_by { _1.tag.name('ja') }
|
||||||
.map { |post_tag|
|
.map { |post_tag|
|
||||||
TagRepr.inline(post_tag.tag).merge(
|
TagRepr.inline(post_tag.tag).merge(
|
||||||
'children' => [],
|
'children' => [],
|
||||||
|
|||||||
@@ -3,18 +3,19 @@
|
|||||||
|
|
||||||
module TagRepr
|
module TagRepr
|
||||||
BASE = { only: [:id, :category, :post_count, :created_at, :updated_at, :deprecated_at],
|
BASE = { only: [:id, :category, :post_count, :created_at, :updated_at, :deprecated_at],
|
||||||
methods: [:name, :has_wiki, :material_id, :has_deerjikists] }.freeze
|
methods: [:has_wiki, :material_id, :has_deerjikists] }.freeze
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def base tag
|
def base tag, language_code: 'ja'
|
||||||
tag.as_json(BASE).merge(aliases: tag.snapshot_aliases,
|
tag.as_json(BASE).merge(name: tag.name(language_code),
|
||||||
parents: tag.parents.map { _1.as_json(BASE) })
|
aliases: tag.snapshot_aliases(language_code),
|
||||||
|
parents: tag.parents.map { inline(_1, language_code:) })
|
||||||
end
|
end
|
||||||
|
|
||||||
def inline tag
|
def inline tag, language_code: 'ja'
|
||||||
tag.as_json(BASE).merge(aliases: [], parents: [])
|
tag.as_json(BASE).merge(name: tag.name(language_code), aliases: [], parents: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def many(tags) = tags.map { |t| base(t) }
|
def many(tags, language_code: 'ja') = tags.map { |tag| base(tag, language_code:) }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class MaterialVersionRecorder < VersionRecorder
|
|||||||
{ url: @record.url,
|
{ url: @record.url,
|
||||||
parent: @record.parent,
|
parent: @record.parent,
|
||||||
tag: @record.tag,
|
tag: @record.tag,
|
||||||
tag_name: @record.tag&.name,
|
tag_name: @record.tag&.name('ja'),
|
||||||
tag_category: @record.tag&.category,
|
tag_category: @record.tag&.category,
|
||||||
source_kind: @record.source_kind,
|
source_kind: @record.source_kind,
|
||||||
source_uri: @record.source_uri,
|
source_uri: @record.source_uri,
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class PostBulkCreator
|
|||||||
PostCreatePreflight.new(
|
PostCreatePreflight.new(
|
||||||
attributes: attributes,
|
attributes: attributes,
|
||||||
thumbnail: thumbnail_for(index, attributes),
|
thumbnail: thumbnail_for(index, attributes),
|
||||||
host: @host).run
|
host: @host).run(locale)
|
||||||
if preflight[:existing_post_id].present?
|
if preflight[:existing_post_id].present?
|
||||||
return {
|
return {
|
||||||
status: 'skipped',
|
status: 'skipped',
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class PostCreatePlan
|
|||||||
direct_tag_specs, tag_sections = parse_direct_tag_specs(locale)
|
direct_tag_specs, tag_sections = parse_direct_tag_specs(locale)
|
||||||
default_tag_specs = build_default_tag_specs(locale, direct_tag_specs)
|
default_tag_specs = build_default_tag_specs(locale, direct_tag_specs)
|
||||||
snapshot_tag_specs = merge_tag_specs(direct_tag_specs + default_tag_specs)
|
snapshot_tag_specs = merge_tag_specs(direct_tag_specs + default_tag_specs)
|
||||||
preload_existing_tags_by_name!(snapshot_tag_specs.map { _1[:name] })
|
preload_existing_tags_by_name!(locale, snapshot_tag_specs.map { _1[:name] })
|
||||||
validate_new_tag_specs!(snapshot_tag_specs)
|
validate_new_tag_specs!(locale, snapshot_tag_specs)
|
||||||
post_tag_specs = expand_parent_tag_specs(locale, snapshot_tag_specs)
|
post_tag_specs = expand_parent_tag_specs(locale, snapshot_tag_specs)
|
||||||
video_ms = normalise_video_ms(snapshot_tag_specs)
|
video_ms = normalise_video_ms(snapshot_tag_specs)
|
||||||
validate_video_sections!(video_ms, tag_sections)
|
validate_video_sections!(video_ms, tag_sections)
|
||||||
@@ -49,7 +49,9 @@ class PostCreatePlan
|
|||||||
tag_names.each do |raw_name|
|
tag_names.each do |raw_name|
|
||||||
tag_name, category, sections = parse_raw_tag_name(locale, raw_name)
|
tag_name, category, sections = parse_raw_tag_name(locale, raw_name)
|
||||||
existing_tag = existing_tags_by_name(locale)[tag_name]
|
existing_tag = existing_tags_by_name(locale)[tag_name]
|
||||||
raise Tag::DeprecatedTagNormalisationError, [existing_tag.name] if existing_tag&.deprecated?
|
if existing_tag&.deprecated?
|
||||||
|
raise Tag::DeprecatedTagNormalisationError, [existing_tag.name(locale.language_code)]
|
||||||
|
end
|
||||||
|
|
||||||
direct_tag_specs << {
|
direct_tag_specs << {
|
||||||
name: tag_name,
|
name: tag_name,
|
||||||
@@ -106,17 +108,18 @@ class PostCreatePlan
|
|||||||
default_tag_specs
|
default_tag_specs
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_new_tag_specs! specs
|
def validate_new_tag_specs! locale, specs
|
||||||
Array(specs).each do |spec|
|
Array(specs).each do |spec|
|
||||||
next if existing_tags_by_name.key?(spec[:name])
|
next if existing_tags_by_name(locale).key?(spec[:name])
|
||||||
|
|
||||||
validate_new_tag_spec!(spec)
|
validate_new_tag_spec!(locale, spec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_new_tag_spec! spec
|
def validate_new_tag_spec! locale, spec
|
||||||
tag_name = TagName.new(name: spec[:name])
|
tag_name = TagName.new(name: spec[:name], language_code: locale.language_code,
|
||||||
tag = Tag.new(category: spec[:category], tag_name:)
|
script_code: locale.script_code, primary_flg: true)
|
||||||
|
tag = Tag.new(category: spec[:category])
|
||||||
return if tag_name.valid? && tag.valid?
|
return if tag_name.valid? && tag.valid?
|
||||||
|
|
||||||
post = Post.new
|
post = Post.new
|
||||||
@@ -139,7 +142,7 @@ class PostCreatePlan
|
|||||||
Tag.expand_parent_tags(existing_snapshot_tags)
|
Tag.expand_parent_tags(existing_snapshot_tags)
|
||||||
.reject(&:deprecated?)
|
.reject(&:deprecated?)
|
||||||
.map { |tag|
|
.map { |tag|
|
||||||
{ name: tag.name,
|
{ name: tag.name(locale.language_code),
|
||||||
category: tag.category.to_sym }
|
category: tag.category.to_sym }
|
||||||
}
|
}
|
||||||
merge_tag_specs(snapshot_tag_specs + expanded_parent_specs)
|
merge_tag_specs(snapshot_tag_specs + expanded_parent_specs)
|
||||||
@@ -161,7 +164,9 @@ class PostCreatePlan
|
|||||||
def existing_tags_by_name locale
|
def existing_tags_by_name locale
|
||||||
@existing_tags_by_name ||= begin
|
@existing_tags_by_name ||= begin
|
||||||
names = tag_names.map { canonical_tag_name_without_sections(locale, _1) }.uniq
|
names = tag_names.map { canonical_tag_name_without_sections(locale, _1) }.uniq
|
||||||
Tag.joins(:tag_name).where(tag_names: { name: names }).index_by(&:name)
|
TagName.where(language_code: locale.language_code, primary_flg: true, name: names)
|
||||||
|
.includes(:tag)
|
||||||
|
.each_with_object({ }) { |tag_name, tags| tags[tag_name.name] = tag_name.tag }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -171,9 +176,11 @@ class PostCreatePlan
|
|||||||
return if missing_names.empty?
|
return if missing_names.empty?
|
||||||
|
|
||||||
existing_tags_by_name(locale).merge!(
|
existing_tags_by_name(locale).merge!(
|
||||||
Tag.joins(:tag_name)
|
TagName.where(language_code: locale.language_code,
|
||||||
.where(tag_names: { name: missing_names })
|
primary_flg: true,
|
||||||
.index_by(&:name))
|
name: missing_names)
|
||||||
|
.includes(:tag)
|
||||||
|
.each_with_object({ }) { |tag_name, tags| tags[tag_name.name] = tag_name.tag })
|
||||||
end
|
end
|
||||||
|
|
||||||
def canonical_tag_name_without_sections locale, raw_name
|
def canonical_tag_name_without_sections locale, raw_name
|
||||||
@@ -266,8 +273,8 @@ class PostCreatePlan
|
|||||||
tag_name = TagName.find_by(language_code: locale.language_code, name:)
|
tag_name = TagName.find_by(language_code: locale.language_code, name:)
|
||||||
return name if !(tag_name) || tag_name.primary?
|
return name if !(tag_name) || tag_name.primary?
|
||||||
|
|
||||||
TagName.find_by!(language_code: locale.language_code,
|
TagName.find_by(language_code: locale.language_code,
|
||||||
tag_id: tag_name.tag_id,
|
tag_id: tag_name.tag_id,
|
||||||
primary_flg: true).name
|
primary_flg: true)&.name || name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class PostCreatePreflight
|
|||||||
@host = host
|
@host = host
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run locale
|
||||||
preview = PostImportPreviewer.new.preview_rows(
|
preview = PostImportPreviewer.new.preview_rows(
|
||||||
rows: [preview_row],
|
rows: [preview_row],
|
||||||
fetch_metadata: false).first
|
fetch_metadata: false).first
|
||||||
@@ -53,7 +53,7 @@ class PostCreatePreflight
|
|||||||
original_created_from: preview[:attributes]['original_created_from'],
|
original_created_from: preview[:attributes]['original_created_from'],
|
||||||
original_created_before: preview[:attributes]['original_created_before'],
|
original_created_before: preview[:attributes]['original_created_before'],
|
||||||
duration: preview[:attributes]['duration'],
|
duration: preview[:attributes]['duration'],
|
||||||
video_ms: preview[:attributes]['video_ms'] }).build!
|
video_ms: preview[:attributes]['video_ms'] }).build!(locale)
|
||||||
|
|
||||||
{
|
{
|
||||||
url: plan[:url],
|
url: plan[:url],
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ class PostCreator
|
|||||||
snapshot_tags = planned_snapshot_tags(locale)
|
snapshot_tags = planned_snapshot_tags(locale)
|
||||||
post_tags = planned_post_tags(locale)
|
post_tags = planned_post_tags(locale)
|
||||||
sections = planned_sections(locale)
|
sections = planned_sections(locale)
|
||||||
TagVersioning.record_tag_snapshots!(snapshot_tags, created_by_user: @actor)
|
TagVersioning.record_tag_snapshots!(
|
||||||
|
snapshot_tags,
|
||||||
|
created_by_user: @actor,
|
||||||
|
language_code: locale.language_code)
|
||||||
post.video_ms = planned_video_ms(locale)
|
post.video_ms = planned_video_ms(locale)
|
||||||
post.save!
|
post.save!
|
||||||
sync_post_tags!(post, post_tags, sections)
|
sync_post_tags!(post, post_tags, sections)
|
||||||
@@ -70,7 +73,8 @@ class PostCreator
|
|||||||
tag_sections: materialise_sections(
|
tag_sections: materialise_sections(
|
||||||
@attributes[:tag_sections] || { },
|
@attributes[:tag_sections] || { },
|
||||||
snapshot_tags,
|
snapshot_tags,
|
||||||
post_tags),
|
post_tags,
|
||||||
|
locale),
|
||||||
normalised_parent_post_ids: @attributes[:normalised_parent_post_ids] || [],
|
normalised_parent_post_ids: @attributes[:normalised_parent_post_ids] || [],
|
||||||
video_ms: @attributes[:video_ms] }
|
video_ms: @attributes[:video_ms] }
|
||||||
else
|
else
|
||||||
@@ -81,15 +85,16 @@ class PostCreator
|
|||||||
|
|
||||||
def build_materialised_plan locale
|
def build_materialised_plan locale
|
||||||
plan = PostCreatePlan.new(attributes: @attributes).build!(locale)
|
plan = PostCreatePlan.new(attributes: @attributes).build!(locale)
|
||||||
snapshot_tags = materialise_tags(plan[:snapshot_tag_specs] || [])
|
snapshot_tags = materialise_tags(locale, plan[:snapshot_tag_specs] || [])
|
||||||
post_tags = materialise_tags(plan[:post_tag_specs] || [])
|
post_tags = materialise_tags(locale, plan[:post_tag_specs] || [])
|
||||||
{
|
{
|
||||||
snapshot_tags: snapshot_tags,
|
snapshot_tags: snapshot_tags,
|
||||||
post_tags: post_tags,
|
post_tags: post_tags,
|
||||||
tag_sections: materialise_sections(
|
tag_sections: materialise_sections(
|
||||||
plan[:tag_sections] || { },
|
plan[:tag_sections] || { },
|
||||||
snapshot_tags,
|
snapshot_tags,
|
||||||
post_tags),
|
post_tags,
|
||||||
|
locale),
|
||||||
normalised_parent_post_ids: plan[:normalised_parent_post_ids] || [],
|
normalised_parent_post_ids: plan[:normalised_parent_post_ids] || [],
|
||||||
video_ms: plan[:video_ms] }
|
video_ms: plan[:video_ms] }
|
||||||
end
|
end
|
||||||
@@ -106,10 +111,10 @@ class PostCreator
|
|||||||
end.values
|
end.values
|
||||||
end
|
end
|
||||||
|
|
||||||
def materialise_sections sections_by_name, snapshot_tags, post_tags
|
def materialise_sections sections_by_name, snapshot_tags, post_tags, locale = Locale.nipponese
|
||||||
tags_by_name = post_tags.index_by(&:name)
|
tags_by_name = post_tags.index_by { _1.name(locale.language_code) }
|
||||||
snapshot_tags.each do |tag|
|
snapshot_tags.each do |tag|
|
||||||
tags_by_name[tag.name] ||= tag
|
tags_by_name[tag.name(locale.language_code)] ||= tag
|
||||||
end
|
end
|
||||||
|
|
||||||
sections_by_name.each_with_object({ }) do |(tag_name, ranges), sections|
|
sections_by_name.each_with_object({ }) do |(tag_name, ranges), sections|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class PostImportPreviewer
|
|||||||
THUMBNAIL_FETCH_WARNING = 'サムネールを取得できませんでした.'.freeze
|
THUMBNAIL_FETCH_WARNING = 'サムネールを取得できませんでした.'.freeze
|
||||||
METADATA_FETCH_WARNING = '自動取得に失敗しました.'.freeze
|
METADATA_FETCH_WARNING = '自動取得に失敗しました.'.freeze
|
||||||
|
|
||||||
def preview_rows rows:, fetch_metadata: true, metadata_cache: { }
|
def preview_rows locale, rows:, fetch_metadata: true, metadata_cache: { }
|
||||||
prepared_rows = rows.map { prepare_row(_1) }
|
prepared_rows = rows.map { prepare_row(_1) }
|
||||||
url_counts = prepared_rows.filter_map { _1[:normal_url] }.tally
|
url_counts = prepared_rows.filter_map { _1[:normal_url] }.tally
|
||||||
existing_posts =
|
existing_posts =
|
||||||
@@ -36,7 +36,7 @@ class PostImportPreviewer
|
|||||||
existing_posts,
|
existing_posts,
|
||||||
url_counts)
|
url_counts)
|
||||||
prepared_rows.map { |row|
|
prepared_rows.map { |row|
|
||||||
preview_row(row,
|
preview_row(locale, row,
|
||||||
fetch_metadata:,
|
fetch_metadata:,
|
||||||
metadata_cache:,
|
metadata_cache:,
|
||||||
existing_posts:,
|
existing_posts:,
|
||||||
@@ -59,7 +59,7 @@ class PostImportPreviewer
|
|||||||
source.merge(url_text: url, normal_url:, url_error: validate_url_safety(normal_url))
|
source.merge(url_text: url, normal_url:, url_error: validate_url_safety(normal_url))
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_row row,
|
def preview_row locale, row,
|
||||||
fetch_metadata:,
|
fetch_metadata:,
|
||||||
metadata_cache:,
|
metadata_cache:,
|
||||||
existing_posts:,
|
existing_posts:,
|
||||||
@@ -124,7 +124,8 @@ class PostImportPreviewer
|
|||||||
|
|
||||||
attributes['url'] = url
|
attributes['url'] = url
|
||||||
validate_basic_data(attributes, validation_errors)
|
validate_basic_data(attributes, validation_errors)
|
||||||
validate_preview_tags(merged_tags(tag_sources, provenance['tags']),
|
validate_preview_tags(locale,
|
||||||
|
merged_tags(tag_sources, provenance['tags']),
|
||||||
validation_errors,
|
validation_errors,
|
||||||
known_tags)
|
known_tags)
|
||||||
validate_parents(attributes['parent_post_ids'], validation_errors, existing_parent_ids)
|
validate_parents(attributes['parent_post_ids'], validation_errors, existing_parent_ids)
|
||||||
@@ -362,11 +363,9 @@ class PostImportPreviewer
|
|||||||
}.compact.uniq
|
}.compact.uniq
|
||||||
return { } if names.empty?
|
return { } if names.empty?
|
||||||
|
|
||||||
Tag.joins(:tag_name)
|
TagName.where(language_code: 'ja', primary_flg: true, name: names)
|
||||||
.where(tag_names: { name: names })
|
.includes(:tag)
|
||||||
.includes(:tag_name)
|
.each_with_object({ }) { |tag_name, tags| tags[tag_name.name] = tag_name.tag }
|
||||||
.to_a
|
|
||||||
.index_by(&:name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_parent_ids prepared_rows
|
def preload_parent_ids prepared_rows
|
||||||
@@ -437,19 +436,21 @@ class PostImportPreviewer
|
|||||||
sources['automatic'].to_s
|
sources['automatic'].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_tag_names raw
|
def preview_tag_names locale, raw
|
||||||
names = raw.to_s.split
|
names = raw.to_s.split
|
||||||
return [] if names.empty?
|
return [] if names.empty?
|
||||||
if names.any? { _1.downcase.start_with?('nico:') }
|
if names.any? { _1.downcase.start_with?('nico:') }
|
||||||
return []
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
names.map { |name| TagName.canonicalise(name.sub(/\[.*\]\z/, '')).first }
|
names.map { |name|
|
||||||
|
TagName.canonicalise(locale, name.sub(/\[.*\]\z/, '')).first
|
||||||
|
}
|
||||||
rescue Tag::SectionLiteralParseError
|
rescue Tag::SectionLiteralParseError
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_preview_tags raw, errors, known_tags
|
def validate_preview_tags locale, raw, errors, known_tags
|
||||||
names = raw.to_s.split
|
names = raw.to_s.split
|
||||||
return if names.empty?
|
return if names.empty?
|
||||||
if names.any? { _1.downcase.start_with?('nico:') }
|
if names.any? { _1.downcase.start_with?('nico:') }
|
||||||
@@ -457,7 +458,9 @@ class PostImportPreviewer
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
parsed = names.map { |name| TagName.canonicalise(name.sub(/\[.*\]\z/, '')).first }
|
parsed = names.map { |name|
|
||||||
|
TagName.canonicalise(locale, name.sub(/\[.*\]\z/, '')).first
|
||||||
|
}
|
||||||
existing = parsed.filter_map { known_tags[_1] }
|
existing = parsed.filter_map { known_tags[_1] }
|
||||||
deprecated = existing.select(&:deprecated?).map(&:name)
|
deprecated = existing.select(&:deprecated?).map(&:name)
|
||||||
errors[:tags] = ["廃止済みタグがあります: #{ deprecated.join(' ') }"] if deprecated.present?
|
errors[:tags] = ["廃止済みタグがあります: #{ deprecated.join(' ') }"] if deprecated.present?
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ class PostMetadataFetcher
|
|||||||
|
|
||||||
existing_tags =
|
existing_tags =
|
||||||
Tag
|
Tag
|
||||||
.joins(:tag_name)
|
.joins(:tag_names)
|
||||||
.where(tag_names: { name: names })
|
.where(tag_names: { language_code: 'ja', primary_flg: true, name: names })
|
||||||
.index_by(&:name)
|
.index_by { _1.name('ja') }
|
||||||
|
|
||||||
names.map { |name|
|
names.map { |name|
|
||||||
tag = existing_tags[name]
|
tag = existing_tags[name]
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
class TagVersionRecorder < VersionRecorder
|
class TagVersionRecorder < VersionRecorder
|
||||||
def self.record! tag:, event_type:, created_by_user:
|
def self.record! tag:, event_type:, created_by_user:, language_code: 'ja'
|
||||||
new(tag:, event_type:, created_by_user:).record!
|
new(tag:, event_type:, created_by_user:, language_code:).record!
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize tag:, event_type:, created_by_user:
|
def initialize tag:, event_type:, created_by_user:, language_code:
|
||||||
super(record: tag, event_type:, created_by_user:)
|
super(record: tag, event_type:, created_by_user:)
|
||||||
|
@language_code = language_code
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -14,10 +15,10 @@ class TagVersionRecorder < VersionRecorder
|
|||||||
def record_key = :tag
|
def record_key = :tag
|
||||||
|
|
||||||
def snapshot_attributes
|
def snapshot_attributes
|
||||||
{ name: @record.name,
|
{ name: @record.name(@language_code),
|
||||||
category: @record.category,
|
category: @record.category,
|
||||||
deprecated_at: @record.deprecated_at,
|
deprecated_at: @record.deprecated_at,
|
||||||
aliases: @record.snapshot_aliases.join(' '),
|
aliases: @record.snapshot_aliases(@language_code).join(' '),
|
||||||
parent_tag_ids: @record.snapshot_parent_tag_ids.join(' ') }
|
parent_tag_ids: @record.snapshot_parent_tag_ids.join(' ') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
class TagVersioning
|
class TagVersioning
|
||||||
def self.record! tag, event_type:, created_by_user:
|
def self.record! tag, event_type:, created_by_user:, language_code: 'ja'
|
||||||
TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
|
TagVersionRecorder.record!(tag:, event_type:, created_by_user:, language_code:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ensure_snapshot! tag, created_by_user:
|
def self.ensure_snapshot! tag, created_by_user:, language_code: 'ja'
|
||||||
return if tag.tag_versions.exists?
|
return if tag.tag_versions.exists?
|
||||||
|
|
||||||
TagVersionRecorder.record!(tag:, event_type: :create, created_by_user:)
|
TagVersionRecorder.record!(tag:, event_type: :create, created_by_user:, language_code:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.record_tag_snapshot! tag, created_by_user:
|
def self.record_tag_snapshot! tag, created_by_user:, language_code: 'ja'
|
||||||
event_type = tag.tag_versions.exists? ? :update : :create
|
event_type = tag.tag_versions.exists? ? :update : :create
|
||||||
record!(tag, event_type:, created_by_user:)
|
record!(tag, event_type:, created_by_user:, language_code:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.record_tag_snapshots! tags, created_by_user:
|
def self.record_tag_snapshots! tags, created_by_user:, language_code: 'ja'
|
||||||
tags.each do |tag|
|
tags.each do |tag|
|
||||||
record_tag_snapshot!(tag, created_by_user:)
|
record_tag_snapshot!(tag, created_by_user:, language_code:)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class TheatrePostSelector
|
|||||||
def weighted_candidates
|
def weighted_candidates
|
||||||
@weighted_candidates ||= begin
|
@weighted_candidates ||= begin
|
||||||
penalties = tag_penalties
|
penalties = tag_penalties
|
||||||
posts = eligible_posts.includes(tags: :tag_name).to_a
|
posts = eligible_posts.includes(tags: :tag_names).to_a
|
||||||
|
|
||||||
posts.map do |post|
|
posts.map do |post|
|
||||||
post_tags = post.tags.to_a
|
post_tags = post.tags.to_a
|
||||||
@@ -82,7 +82,7 @@ class TheatrePostSelector
|
|||||||
def tag_penalty_json
|
def tag_penalty_json
|
||||||
return [] if tag_penalties.empty?
|
return [] if tag_penalties.empty?
|
||||||
|
|
||||||
tags = Tag.where(id: tag_penalties.keys).includes(:tag_name).index_by(&:id)
|
tags = Tag.where(id: tag_penalties.keys).includes(:tag_names).index_by(&:id)
|
||||||
|
|
||||||
tag_penalties
|
tag_penalties
|
||||||
.map { |tag_id, penalty|
|
.map { |tag_id, penalty|
|
||||||
@@ -113,7 +113,7 @@ class TheatrePostSelector
|
|||||||
|
|
||||||
def light_tag_json tag
|
def light_tag_json tag
|
||||||
{ id: tag.id,
|
{ id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name('ja'),
|
||||||
category: tag.category }
|
category: tag.category }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする