CDB-3837 Rake ready

pull/682/head
Kartones 10 years ago
parent ef0078a308
commit cf6f1ae696

@ -4,6 +4,39 @@
namespace :cartodb do
namespace :overlays do
desc 'removes duplicated overlays from visualizations'
task :remove_duplicate_overlays => :environment do |t, args|
count = 0
unique_types = CartoDB::Overlay::Member::UNIQUE_TYPES
CartoDB::Visualization::Collection.new.fetch({ per_page: 999999 }).each { |vis|
if vis.user
begin
overlays_counts = {}
if !vis.overlays.nil? && vis.overlays.count > 0
vis.overlays.each { |overlay|
if !overlays_counts[overlay.type].present?
overlays_counts[overlay.type] = 1
else
if unique_types.include?(overlay.type)
puts "Found duplicate for #{vis.id} of type '#{overlay.type}'"
overlay.delete
else
overlays_counts[overlay.type]+=1
end
end
}
end
if count % 500 == 0
puts "Progress: #{count}"
end
count+=1
rescue => e
puts "ERROR: failed to remove duplicate overlays for #{vis.id}: #{e.message}"
end
end
}
end
desc 'create overlays from url_options'
task :create_overlays, [:clear_overlays] => :environment do |t, args|
ok = 0

Loading…
Cancel
Save