split out code to dedupe tags

This commit is contained in:
Kyle Drake 2020-05-26 22:48:24 -07:00
parent f32ef0a292
commit 0eba98bffd

View file

@ -184,6 +184,24 @@ task :primenewstriperunonlyonce => [:environment] do
end 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' desc 'Clean tags'
task :cleantags => [:environment] do task :cleantags => [:environment] do
@ -208,21 +226,6 @@ task :cleantags => [:environment] do
end end
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 Tag.where(name: 'porn').first.update is_nsfw: true
end end