From 1487a260d104d4d166f9b10dd7303d26bb6bd0a5 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 30 Jun 2016 12:17:16 +0300 Subject: [PATCH] Story#119627029 - update algorithm how we merge existing legal doc files (cherry picked from commit 77de3ad) --- lib/tasks/legal_doc.rake | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/tasks/legal_doc.rake b/lib/tasks/legal_doc.rake index de8bfa784..4597b1186 100644 --- a/lib/tasks/legal_doc.rake +++ b/lib/tasks/legal_doc.rake @@ -32,19 +32,16 @@ namespace :legal_doc do modified = Array.new LegalDocument.where.not(checksum: [nil, ""]).find_each do |x| - if File.exist?(x.path) + next if modified.include?(x.checksum) + next if !File.exist?(x.path) + modified.push(x.checksum) - LegalDocument.where(checksum: x.checksum) do |y| - if x.id != y.id && !modified.include?(x.id) - - File.delete(y.path) if File.exist?(y.path) - y.path = x.path - y.save - modified.push(y.id) - count += 1 - - end + LegalDocument.where(checksum: x.checksum).where.not(id: x.id) do |y| + unless modified.include?(x.id) + File.delete(y.path) if File.exist?(y.path) + y.update(path: x.path) + count += 1 end end end