mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-30 20:23:14 +08:00
generates query in background worker
This commit is contained in:
parent
8bbac0e3ab
commit
e1ee53eeb5
1 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue