aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm2
-rw-r--r--perllib/FixMyStreet/Roles/ContactExtra.pm6
2 files changed, 6 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 00fe7dd7a..f92a5cb22 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -614,7 +614,7 @@ sub setup_categories_and_bodies : Private {
= $c #
->model('DB::Contact') #
->active
- ->search( { body_id => [ keys %bodies ] } );
+ ->search( { body_id => [ keys %bodies ] }, { prefetch => 'body' } );
my @contacts = $c->cobrand->categories_restriction($contacts)->all;
# variables to populate
diff --git a/perllib/FixMyStreet/Roles/ContactExtra.pm b/perllib/FixMyStreet/Roles/ContactExtra.pm
index fc6531e54..55c055d99 100644
--- a/perllib/FixMyStreet/Roles/ContactExtra.pm
+++ b/perllib/FixMyStreet/Roles/ContactExtra.pm
@@ -15,6 +15,7 @@ sub for_bodies {
my $filters = {
order_by => $order,
join => { $join_table => 'contact' },
+ prefetch => $join_table,
distinct => 1,
};
if ($category) {
@@ -33,7 +34,10 @@ sub by_categories {
foreach my $contact (@contacts) {
my $join_table = $rs->join_table();
- my @ts = grep { !defined($_->$join_table->first) || $_->$join_table->find({contact_id => $contact->get_column('id')}) } @results;
+ my @ts = grep {
+ $_->$join_table == 0 # There's no category at all on this defect type/template/priority
+ || (grep { $_->contact_id == $contact->get_column('id') } $_->$join_table)
+ } @results;
@ts = $rs->map_extras(@ts);
$extras{$contact->category} = encode_json(\@ts);
}