mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
split out code to dedupe tags
This commit is contained in:
parent
f32ef0a292
commit
0eba98bffd
1 changed files with 18 additions and 15 deletions
33
Rakefile
33
Rakefile
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue