mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Story#119627029 - more efficient update of checksums of existing records
(cherry picked from commit 8127181
)
This commit is contained in:
parent
71547d91a3
commit
2e4e07503f
1 changed files with 3 additions and 5 deletions
|
@ -8,17 +8,15 @@ namespace :legal_doc do
|
||||||
|
|
||||||
desc 'Generate hash'
|
desc 'Generate hash'
|
||||||
task generate_hash: :environment do
|
task generate_hash: :environment do
|
||||||
|
|
||||||
start = Time.zone.now.to_f
|
start = Time.zone.now.to_f
|
||||||
puts '-----> Generating unique hash for legal documents'
|
puts '-----> Generating unique hash for legal documents'
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
LegalDocument.find_each do |x|
|
LegalDocument.where(checksum: [nil, ""]).find_each do |x|
|
||||||
|
if File.exist?(x.path)
|
||||||
if File.exist?(x.path) && x.body_hash.blank?
|
|
||||||
digest = Digest::SHA1.new
|
digest = Digest::SHA1.new
|
||||||
digest.update File.binread(x.path)
|
digest.update File.binread(x.path)
|
||||||
x.checksum = digest.hexdigest
|
x.checksum = digest.to_s
|
||||||
x.save
|
x.save
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue