diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-18 18:44:32 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-18 19:22:48 +0100 |
commit | 20f93425b278ee2cd54b90cab6eb3e69c4921e73 (patch) | |
tree | 0b14068745a0e24435110423a68e491afd9e5b19 | |
parent | 382326968ae1ee5a5226dfe0d52e13f02a292c0f (diff) |
Cache Problem->bodies and prefetch the body areas.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 21 |
2 files changed, 15 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index a410c2d91..c617f5733 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -441,6 +441,7 @@ sub inspect : Private { # This problem might no longer be visible on the current cobrand, # if its body has changed (e.g. by virtue of the category changing) # so redirect to a cobrand where it can be seen if necessary + $problem->discard_changes; my $redirect_uri; if ( $c->cobrand->is_council && !$c->cobrand->owns_problem($problem) ) { $redirect_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 720e8cc93..19e76f6ed 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -502,13 +502,20 @@ Returns a hashref of bodies to which a report was sent. =cut -sub bodies($) { - my $self = shift; - return {} unless $self->bodies_str; - my $bodies = $self->bodies_str_ids; - my @bodies = $self->result_source->schema->resultset('Body')->search({ id => $bodies })->all; - return { map { $_->id => $_ } @bodies }; -} +has bodies => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + return {} unless $self->bodies_str; + my $bodies = $self->bodies_str_ids; + my @bodies = $self->result_source->schema->resultset('Body')->search( + { id => $bodies }, + { prefetch => 'body_areas' }, + )->all; + return { map { $_->id => $_ } @bodies }; + }, +); sub body_names($) { my $self = shift; |