add back tag dedupe code

This commit is contained in:
Kyle Drake 2024-08-14 12:56:14 -05:00
parent 4fc5698d0e
commit 4eeec12b67
2 changed files with 19 additions and 1 deletions

View file

@ -238,3 +238,21 @@ task :generate_sitemap => [:environment] do
gz.write %{</sitemapindex>}
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

View file

@ -904,7 +904,7 @@ class Site < Sequel::Model
end
def add_tag_name(name)
add_tag Tag[name: name] || Tag.create(name: name)
add_tag Tag.find_or_create(name: name)
end
def before_create