Skip to content

Commit

Permalink
Proof of concept to show if splitting up the coercion helps
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrett committed Jul 19, 2023
1 parent ec6e993 commit 30d83c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ class User < ApplicationRecord
registered_at
].freeze

def self.csv_headers
if Rails.application.cms?
Training::Module.ordered.reject(&:draft?).map { |mod| "module_#{mod.position}_time" }
else
TrainingModule.published.map { |mod| "module_#{mod.id}_time" }
end
end

# Collate published module state and profile data in CSV format
#
# @overload to_csv
# @see ToCsv.to_csv
# @return [String]
def self.to_csv
module_headings =
if Rails.application.cms?
Training::Module.ordered.reject(&:draft?).map { |mod| "module_#{mod.position}_time" }
else
TrainingModule.published.map { |mod| "module_#{mod.id}_time" }
end

CSV.generate(headers: true) do |csv|
csv << (DASHBOARD_ATTRS + module_headings)
csv << (DASHBOARD_ATTRS + csv_headers)
unformatted = dashboard.find_each(batch_size: 1000).map(&:dashboard_attributes)
formatted = CoercionDecorator.new(unformatted).call
formatted = unformatted.each_slice(1000) {|unformatted_slice| CoercionDecorator.new(unformatted_slice).call }
formatted.each { |row| csv << row.values }
end
end
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30d83c8

Please sign in to comment.