diff options
author | Dave Arter <davea@mysociety.org> | 2017-08-18 12:31:28 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-08-18 15:20:57 +0100 |
commit | 6a2734fb46c9edebe6d455c4ab1984065cc64485 (patch) | |
tree | 016e2e9b6ac5e4c05841a05585d14ab959769df4 | |
parent | f1859bc10aaa153568ea866142c8535cbf769b87 (diff) |
Reduce queries on /report when loading defect types/priorities
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/ContactExtra.pm | 6 |
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); } |