Skip to content

Commit 52ddf4e

Browse files
committed
Use find_each in reports
Where possible, this should improve the memory usage of the reporting.
1 parent 0382e28 commit 52ddf4e

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

app/lib/reports/offline_session_exporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def add_vaccinations_sheet(package)
4848
workbook.add_worksheet(name: "Vaccinations") do |sheet|
4949
sheet.add_row(columns.map { _1.to_s.upcase })
5050

51-
patient_sessions.each do |patient_session|
51+
patient_sessions.find_each do |patient_session|
5252
rows(patient_session:).each { |row| row.add_to(sheet:, cached_styles:) }
5353
end
5454

app/lib/reports/programme_vaccinations_exporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(organisation:, programme:, start_date:, end_date:)
1212

1313
def call
1414
CSV.generate(headers:, write_headers: true) do |csv|
15-
vaccination_records.each do |vaccination_record|
15+
vaccination_records.find_each do |vaccination_record|
1616
csv << row(vaccination_record:)
1717
end
1818
end

app/lib/reports/systm_one_exporter.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ def initialize(organisation:, programme:, start_date:, end_date:)
3434

3535
def call
3636
CSV.generate(headers:, write_headers: true) do |csv|
37-
vaccination_records.each do |vaccination_record|
37+
vaccination_records.find_each do |vaccination_record|
3838
csv << row(vaccination_record:)
3939
end
4040
end
4141
end
4242

43-
def self.call(*args, **kwargs)
44-
new(*args, **kwargs).call
45-
end
43+
def self.call(...) = new(...).call
4644

4745
private_class_method :new
4846

0 commit comments

Comments
 (0)