From 03dc4d0661dc7220dedc7260e0506c79cd6669fd Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 18 Jul 2026 13:32:22 +0900 Subject: [PATCH] #399 --- backend/app/services/post_create_plan.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/app/services/post_create_plan.rb b/backend/app/services/post_create_plan.rb index 4126765..c660e21 100644 --- a/backend/app/services/post_create_plan.rb +++ b/backend/app/services/post_create_plan.rb @@ -12,6 +12,7 @@ class PostCreatePlan direct_tag_specs, tag_sections = parse_direct_tag_specs default_tag_specs = build_default_tag_specs(direct_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] }) validate_new_tag_specs!(snapshot_tag_specs) post_tag_specs = expand_parent_tag_specs(snapshot_tag_specs) video_ms = normalise_video_ms(snapshot_tag_specs) @@ -161,6 +162,17 @@ class PostCreatePlan end end + def preload_existing_tags_by_name! names + wanted_names = Array(names).map { _1.to_s }.reject(&:blank?).uniq + missing_names = wanted_names - existing_tags_by_name.keys + return if missing_names.empty? + + existing_tags_by_name.merge!( + Tag.joins(:tag_name) + .where(tag_names: { name: missing_names }) + .index_by(&:name)) + end + def canonical_tag_name_without_sections raw_name name, = parse_raw_tag_name(raw_name) name