mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Log timing in import script
This commit is contained in:
parent
e195d3948e
commit
ecee4fa64c
1 changed files with 9 additions and 7 deletions
|
@ -1,15 +1,17 @@
|
||||||
namespace :import do
|
namespace :import do
|
||||||
desc 'Imports registrars'
|
desc 'Imports registrars'
|
||||||
task registrars: :environment do
|
task registrars: :environment do
|
||||||
|
start = Time.now.to_f
|
||||||
puts '-----> Importing registrars...'
|
puts '-----> Importing registrars...'
|
||||||
|
|
||||||
Registrar.where('legacy_id IS NOT NULL').delete_all
|
|
||||||
|
|
||||||
registrars = []
|
registrars = []
|
||||||
existing_ids = Registrar.pluck(:legacy_id)
|
existing_ids = Registrar.pluck(:legacy_id)
|
||||||
|
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
||||||
|
count = 0
|
||||||
|
|
||||||
Legacy::Registrar.all.each do |x|
|
Legacy::Registrar.all.each do |x|
|
||||||
next if existing_ids.include?(x.id)
|
next if existing_ids.include?(x.id)
|
||||||
|
count += 1
|
||||||
|
|
||||||
registrars << Registrar.new({
|
registrars << Registrar.new({
|
||||||
name: x.organization.try(:strip).presence || x.name.try(:strip).presence || x.handle.try(:strip).presence,
|
name: x.organization.try(:strip).presence || x.name.try(:strip).presence || x.handle.try(:strip).presence,
|
||||||
|
@ -28,19 +30,19 @@ namespace :import do
|
||||||
directo_handle: x.directo_handle.try(:strip),
|
directo_handle: x.directo_handle.try(:strip),
|
||||||
vat: x.vat,
|
vat: x.vat,
|
||||||
legacy_id: x.id,
|
legacy_id: x.id,
|
||||||
creator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
|
creator_str: user,
|
||||||
updator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
updator_str: user
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
Registrar.import registrars, validate: false
|
Registrar.import registrars, validate: false
|
||||||
|
|
||||||
puts '-----> Registrars imported'
|
puts "-----> Imported #{count} new registrars in #{(Time.now.to_f - start).round(2)} seconds"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Import contacts'
|
desc 'Import contacts'
|
||||||
task contacts: :environment do
|
task contacts: :environment do
|
||||||
start = Time.now.to_i
|
start = Time.now.to_f
|
||||||
puts '-----> Importing contacts...'
|
puts '-----> Importing contacts...'
|
||||||
|
|
||||||
# 1;"RC";"born number" # not used
|
# 1;"RC";"born number" # not used
|
||||||
|
@ -147,6 +149,6 @@ namespace :import do
|
||||||
|
|
||||||
puts '-----> Updating relations...'
|
puts '-----> Updating relations...'
|
||||||
ActiveRecord::Base.connection.execute('UPDATE addresses SET contact_id = legacy_contact_id WHERE legacy_contact_id IS NOT NULL AND contact_id IS NULL')
|
ActiveRecord::Base.connection.execute('UPDATE addresses SET contact_id = legacy_contact_id WHERE legacy_contact_id IS NOT NULL AND contact_id IS NULL')
|
||||||
puts "-----> Imported #{count} new contacts in #{Time.now.to_i - start} seconds"
|
puts "-----> Imported #{count} new contacts in #{(Time.now.to_f - start).round(2)} seconds"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue