From 0eba98bffd6d4630f2a5a360d134a3378371cac3 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 26 May 2020 22:48:24 -0700 Subject: [PATCH] split out code to dedupe tags --- Rakefile | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Rakefile b/Rakefile index 6a8f06a8..96f01872 100644 --- a/Rakefile +++ b/Rakefile @@ -184,6 +184,24 @@ task :primenewstriperunonlyonce => [:environment] do end +desc 'dedupe tags' +task :dedupetags => [:environment] do + Tag.all.each do |tag| + begin + tag.reload + rescue Sequel::Error => e + next if e.message =~ /Record not found/ + end + + matching_tags = Tag.exclude(id: tag.id).where(name: tag.name).all + + matching_tags.each do |matching_tag| + DB[:sites_tags].where(tag_id: matching_tag.id).update(tag_id: tag.id) + matching_tag.delete + end + end +end + desc 'Clean tags' task :cleantags => [:environment] do @@ -208,21 +226,6 @@ task :cleantags => [:environment] do end end - Tag.all.each do |tag| - begin - tag.reload - rescue Sequel::Error => e - next if e.message =~ /Record not found/ - end - - matching_tags = Tag.exclude(id: tag.id).where(name: tag.name).all - - matching_tags.each do |matching_tag| - DB[:sites_tags].where(tag_id: matching_tag.id).update(tag_id: tag.id) - matching_tag.delete - end - end - Tag.where(name: 'porn').first.update is_nsfw: true end