mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Story#119627029 - more efficient legal doc search by checksum
(cherry picked from commit 952d15d
)
This commit is contained in:
parent
9b6bd22be3
commit
71547d91a3
2 changed files with 6 additions and 6 deletions
|
@ -34,9 +34,9 @@ class LegalDocument < ActiveRecord::Base
|
|||
def save_to_filesystem
|
||||
digest = Digest::SHA1.new
|
||||
binary = Base64.decode64(body)
|
||||
ld = LegalDocument.where(checksum: digest.update(binary))
|
||||
ld = LegalDocument.find_by(checksum: digest.update(binary))
|
||||
|
||||
if !ld
|
||||
if ld.nil?
|
||||
loop do
|
||||
rand = SecureRandom.random_number.to_s.last(4)
|
||||
next if rand.to_i == 0 || rand.length < 4
|
||||
|
@ -49,10 +49,9 @@ class LegalDocument < ActiveRecord::Base
|
|||
|
||||
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
|
||||
self.path = path
|
||||
|
||||
else
|
||||
|
||||
self.path = ld.first.path
|
||||
|
||||
self.path = ld.path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class AddHashToLegalDoc < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :legal_documents, :checksum, :text
|
||||
add_column :legal_documents, :checksum, :string
|
||||
add_index :legal_documents, :checksum
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue