From e1ee53eeb5d8f9d5d0e45c4a0cd1d5d2c39c957b Mon Sep 17 00:00:00 2001 From: zmagod Date: Mon, 3 Apr 2017 13:37:54 +0200 Subject: [PATCH] generates query in background worker --- app/models/zip_export.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/zip_export.rb b/app/models/zip_export.rb index f6215808f..a1acefca0 100644 --- a/app/models/zip_export.rb +++ b/app/models/zip_export.rb @@ -51,15 +51,17 @@ class ZipExport < ActiveRecord::Base private def fill_content(dir, data, type, options = {}) - generate_csv(dir, data, options) if type == :csv + generate_papertrail_csv(dir, data, options) if type == :papertrail end - def generate_csv(tmp_dir, data, options = {}) + def generate_papertrail_csv(tmp_dir, data, options = {}) attributes = options.fetch(:attributes) { :attributes_missing } file = FileUtils.touch("#{tmp_dir}/export.csv").first + records = PaperTrail::Version.where(data) + .order(created_at: :desc) CSV.open(file, 'wb') do |csv| csv << attributes - data.each do |entity| + records.find_each do |entity| csv << entity.audit_record.values_at(*attributes.map(&:to_sym)) end end