mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +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'
|
||||
task generate_hash: :environment do
|
||||
|
||||
start = Time.zone.now.to_f
|
||||
puts '-----> Generating unique hash for legal documents'
|
||||
count = 0
|
||||
|
||||
LegalDocument.find_each do |x|
|
||||
|
||||
if File.exist?(x.path) && x.body_hash.blank?
|
||||
LegalDocument.where(checksum: [nil, ""]).find_each do |x|
|
||||
if File.exist?(x.path)
|
||||
digest = Digest::SHA1.new
|
||||
digest.update File.binread(x.path)
|
||||
x.checksum = digest.hexdigest
|
||||
x.checksum = digest.to_s
|
||||
x.save
|
||||
count += 1
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue