aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-12-13 20:15:54 +0000
committerLouise Crow <louise.crow@gmail.com>2012-12-13 20:15:54 +0000
commitd2dc193066222b279faa52a66a22760e739dd87e (patch)
tree603a0437ac502b827c9b08eb5c1d3764ed72ce1d
parent611411fc7907a97e3aa8c2339bc9f5b70a5d1a01 (diff)
Put download zips in a predictable location - sharded folders based on request ID, rather than distributing them across the download directories by the generated SHA. Preserve the uniqueness of the subdirectory.
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/request_controller.rb5
2 files changed, 9 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 239d49a6c..d8f7f9ea7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -229,6 +229,11 @@ class ApplicationController < ActionController::Base
end
end
+ def request_dirs(info_request)
+ first_three_digits = info_request.id.to_s()[0..2]
+ File.join(first_three_digits.to_s, info_request.id.to_s)
+ end
+
def download_zip_dir()
File.join(Rails.root, '/cache/zips/')
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 42cfa11c6..d8c34c2dd 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -882,7 +882,10 @@ class RequestController < ApplicationController
:info_request_title=>@info_request.title)
)
updated = Digest::SHA1.hexdigest(@info_request.get_last_event.created_at.to_i.to_s + @info_request.updated_at.to_i.to_s)
- @url_path = "/download/#{updated[0..1]}/#{updated}/#{params[:url_title]}.zip"
+ @url_path = File.join("/download",
+ request_dirs(@info_request),
+ updated,
+ "#{params[:url_title]}.zip")
file_path = File.expand_path(File.join(download_zip_dir(), @url_path))
if !File.exists?(file_path)
FileUtils.mkdir_p(File.dirname(file_path))