aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Dashboard.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-03-05 15:31:09 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-03-05 15:31:09 +0000
commit1e67b3fea57ee8560d0741c96bc5702c90980dad (patch)
tree8832c960fe9b51ad23cd2222fd97640107760c79 /perllib/FixMyStreet/App/Controller/Dashboard.pm
parent88bbf7cbd2621565813bcdc1400f42b82ffe9de2 (diff)
parentbbc3c3d013a1f00da59cfc982da24865e94ca2b0 (diff)
Merge branch 'stream-csv-output'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Dashboard.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm36
1 files changed, 25 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index a7de23ce3..bd60f8570 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -3,6 +3,7 @@ use Moose;
use namespace::autoclean;
use DateTime;
+use Encode;
use JSON::MaybeXS;
use Path::Tiny;
use Text::CSV;
@@ -409,12 +410,29 @@ hashref of extra data to include that can be used by 'columns'.
sub generate_csv : Private {
my ($self, $c) = @_;
+ my $filename = $c->stash->{csv}->{filename};
+ $c->res->content_type('text/csv; charset=utf-8');
+ $c->res->header('content-disposition' => "attachment; filename=\"${filename}.csv\"");
+
+ # Emit a header (copying Drupal's naming) telling an intermediary (e.g.
+ # Varnish) not to buffer the output. Varnish will need to know this, e.g.:
+ # if (beresp.http.Surrogate-Control ~ "BigPipe/1.0") {
+ # set beresp.do_stream = true;
+ # set beresp.ttl = 0s;
+ # }
+ $c->res->header('Surrogate-Control' => 'content="BigPipe/1.0"');
+
+ # Tell nginx not to buffer this response
+ $c->res->header('X-Accel-Buffering' => 'no');
+
+ # Define an empty body so the web view doesn't get added at the end
+ $c->res->body("");
+
# Old parameter renaming
$c->stash->{csv}->{objects} //= $c->stash->{csv}->{problems};
my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
- $csv->combine(@{$c->stash->{csv}->{headers}});
- my @body = ($csv->string);
+ $csv->print($c->response, $c->stash->{csv}->{headers});
my $fixed_states = FixMyStreet::DB::Result::Problem->fixed_states;
my $closed_states = FixMyStreet::DB::Result::Problem->closed_states;
@@ -468,19 +486,15 @@ sub generate_csv : Private {
$hashref = { %$hashref, %$extra };
}
- $csv->combine(
+ $csv->print($c->response, [
+ map {
+ $_ = encode('UTF-8', $_) if $_;
+ }
@{$hashref}{
@{$c->stash->{csv}->{columns}}
},
- );
-
- push @body, $csv->string;
+ ] );
}
-
- my $filename = $c->stash->{csv}->{filename};
- $c->res->content_type('text/csv; charset=utf-8');
- $c->res->header('content-disposition' => "attachment; filename=\"${filename}.csv\"");
- $c->res->body( join "", @body );
}
=head1 AUTHOR