Merge pull request #3096 from techAPJ/patch-1

gzip csv export files
This commit is contained in:
Régis Hanol 2015-01-14 09:23:15 +01:00
commit b34ef26f90
2 changed files with 7 additions and 5 deletions

View File

@ -288,12 +288,14 @@ module Jobs
csv << value
end
end
# compress CSV file
`gzip --best #{File.expand_path("#{UserExport.base_directory}/#{@file_name}", __FILE__)}`
end
def notify_user
if @current_user
if @file_name != "" && File.exists?("#{UserExport.base_directory}/#{@file_name}")
SystemMessage.create_from_system_user(@current_user, :csv_export_succeeded, download_link: "#{Discourse.base_url}/export_csv/#{@file_name}", file_name: @file_name)
if @file_name != "" && File.exists?("#{UserExport.base_directory}/#{@file_name}.gz")
SystemMessage.create_from_system_user(@current_user, :csv_export_succeeded, download_link: "#{Discourse.base_url}/export_csv/#{@file_name}.gz", file_name: "#{@file_name}.gz")
else
SystemMessage.create_from_system_user(@current_user, :csv_export_failed)
end

View File

@ -1,7 +1,7 @@
require "spec_helper"
describe ExportCsvController do
let(:export_filename) { "user-archive-999.csv" }
let(:export_filename) { "user-archive-999.csv.gz" }
context "while logged in as normal user" do
@ -30,7 +30,7 @@ describe ExportCsvController do
describe ".download" do
it "uses send_file to transmit the export file" do
file = UserExport.create(export_type: "user", user_id: @user.id)
file_name = "user-archive-#{file.id}.csv"
file_name = "user-archive-#{file.id}.csv.gz"
controller.stubs(:render)
export = UserExport.new()
UserExport.expects(:get_download_path).with(file_name).returns(export)
@ -74,7 +74,7 @@ describe ExportCsvController do
describe ".download" do
it "uses send_file to transmit the export file" do
file = UserExport.create(export_type: "admin", user_id: @admin.id)
file_name = "screened-email-#{file.id}.csv"
file_name = "screened-email-#{file.id}.csv.gz"
controller.stubs(:render)
export = UserExport.new()
UserExport.expects(:get_download_path).with(file_name).returns(export)