Merge pull request #310 from internetee/119627029-legal_doc_dublicates-2

119627029 legal doc dublicates 2
This commit is contained in:
Timo Võhmar 2016-12-23 14:12:00 +02:00 committed by GitHub
commit c1cb598da1
7 changed files with 327 additions and 47 deletions

35
lib/tasks/legal_doc.rake Normal file
View file

@ -0,0 +1,35 @@
namespace :legal_doc do
desc 'Legal documents duplicates fix'
task all: :environment do
Rake::Task['legal_doc:generate_hash'].invoke
Rake::Task['legal_doc:remove_duplicates'].invoke
end
desc 'Generate hash'
task generate_hash: :environment do
start = Time.zone.now.to_f
puts '-----> Generating unique hash for legal documents'
count = 0
LegalDocument.where(checksum: [nil, ""]).find_each do |x|
if File.exist?(x.path)
x.checksum = x.calc_checksum
x.save
count += 1
end
end
puts "-----> Hash generated for #{count} rows in #{(Time.zone.now.to_f - start).round(2)} seconds"
end
# Starting point is Domain legal docs
# then inside it checking the same domains and connected contacts
desc 'Remove duplicates'
task remove_duplicates: :environment do
LegalDocument.remove_duplicates
end
end