@@ -24,7 +24,7 @@ def download_template
2424 headers [ 'Content-Disposition' ] = "attachment; filename=\" #{ current_exhibit . slug } -bulk-update-template.csv\" "
2525 headers . delete ( 'Content-Length' )
2626
27- self . response_body = csv_template
27+ stream_csv_template
2828 end
2929
3030 def update
@@ -43,16 +43,31 @@ def monitor
4343
4444 private
4545
46+ def stream_csv_template
47+ csv_template . each do |row |
48+ response . stream . write row
49+ end
50+ ensure
51+ response . stream . close
52+ end
53+
4654 def csv_template
47- boolean = ActiveModel ::Type ::Boolean . new
48- Spotlight ::BulkUpdatesCsvTemplateService . new ( exhibit : current_exhibit ) . template (
49- view_context :,
50- title : boolean . cast ( reference_field_params [ :item_title ] ) ,
51- tags : boolean . cast ( updatable_field_params [ :tags ] ) ,
52- visibility : boolean . cast ( updatable_field_params [ :visibility ] )
55+ @csv_template ||= csv_template_service . template (
56+ view_context : view_context ,
57+ title : active_model_boolean . cast ( reference_field_params [ :item_title ] ) ,
58+ visibility : active_model_boolean . cast ( updatable_field_params [ :visibility ] ) ,
59+ tags : active_model_boolean . cast ( updatable_field_params [ :tags ] )
5360 )
5461 end
5562
63+ def csv_template_service
64+ @csv_template_service ||= Spotlight ::BulkUpdatesCsvTemplateService . new ( exhibit : current_exhibit )
65+ end
66+
67+ def active_model_boolean
68+ @active_model_boolean ||= ActiveModel ::Type ::Boolean . new
69+ end
70+
5671 def reference_field_params
5772 params . require ( :reference_fields ) . permit ( :item_title )
5873 end
0 commit comments