From 6cec86ddbde29cd5ed8a42cfc57d3a785d39c80d Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 13 Jul 2025 18:07:06 +0900 Subject: [PATCH] #77 --- backend/lib/tasks/sync_nico.rake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/lib/tasks/sync_nico.rake b/backend/lib/tasks/sync_nico.rake index 1aadd48..0a102a9 100644 --- a/backend/lib/tasks/sync_nico.rake +++ b/backend/lib/tasks/sync_nico.rake @@ -44,13 +44,16 @@ namespace :nico do new_tags = datum['tags'].map { |tag| "nico:#{ tag }" }.sort if current_tags != new_tags post.tags.destroy(post.tags.where(name: current_tags)) + tags_to_add = [] new_tags.each do |name| - post.tags << Tag.find_or_initialize_by(name:) do |tag| - tag.category = 'nico' + tag = Tag.find_or_initialize_by(name:) do |t| + t.category = 'nico' end + tags_to_add.concat([tag] + tag.linked_tags) end - post.tags << Tag.tagme if post.tags.size < 20 && post.tags.none?(Tag.tagme) - post.tags << Tag.bot if post.tags.none?(Tag.bot) + tags_to_add << Tag.tagme if post.tags.size < 20 + tags_to_add << Tag.bot + post.tags.concat(tags_to_add).uniq! end end end