aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/Problem.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm27
1 files changed, 14 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 2deeb3084..fac0fc7ef 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -653,7 +653,8 @@ sub body {
my $body;
if ($problem->external_body) {
if ($problem->cobrand eq 'zurich') {
- $body = $c->model('DB::Body')->find({ id => $problem->external_body });
+ my $cache = $problem->result_source->schema->cache;
+ return $cache->{bodies}{$problem->external_body} //= $c->model('DB::Body')->find({ id => $problem->external_body });
} else {
$body = $problem->external_body;
}
@@ -918,12 +919,11 @@ sub add_send_method {
}
sub as_hashref {
- my $self = shift;
- my $c = shift;
+ my ($self, $c, $cols) = @_;
my $state_t = FixMyStreet::DB->resultset("State")->display($self->state);
- return {
+ my $out = {
id => $self->id,
title => $self->title,
category => $self->category,
@@ -935,16 +935,17 @@ sub as_hashref {
state => $self->state,
state_t => $state_t,
used_map => $self->used_map,
- is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0,
- photos => [ map { $_->{url} } @{$self->photos} ],
- meta => $self->confirmed ? $self->meta_line( $c ) : '',
- ($self->confirmed ? (
- confirmed => $self->confirmed,
- confirmed_pp => $c->cobrand->prettify_dt( $self->confirmed ),
- ) : ()),
- created => $self->created,
- created_pp => $c->cobrand->prettify_dt( $self->created ),
+ created => $self->created,
};
+ $out->{is_fixed} = $self->fixed_states->{ $self->state } ? 1 : 0 if !$cols || $cols->{is_fixed};
+ $out->{photos} = [ map { $_->{url} } @{$self->photos} ] if !$cols || $cols->{photos};
+ $out->{meta} = $self->confirmed ? $self->meta_line( $c ) : '' if !$cols || $cols->{meta};
+ $out->{created_pp} = $c->cobrand->prettify_dt( $self->created ) if !$cols || $cols->{created_pp};
+ if ($self->confirmed) {
+ $out->{confirmed} = $self->confirmed if !$cols || $cols->{confirmed};
+ $out->{confirmed_pp} = $c->cobrand->prettify_dt( $self->confirmed ) if !$cols || $cols->{confirmed_pp};
+ }
+ return $out;
}
=head2 latest_moderation_log_entry