aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-04-30 13:51:42 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-05-06 15:59:03 +0100
commit683b188b288fe43526e1649c784fa44435559655 (patch)
tree5d446f1daa1e96afabec060b0e3e678a8582ea27 /perllib/FixMyStreet/App/Controller/Admin.pm
parent30dfd35daaf0424b2e2bc126485952c26ac9d310 (diff)
Move per-row Contact lookup to the database.
On admin report lists, and in front-end lists when an inspector, each row was querying the database for `category_display`. We create a new relationship for this query, and join/prefetch it wherever we request this data. Include staff joins on /around page, copying what happens on /reports to prevent more lookups there too. Also add some joins for user email in admin report list.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm14
1 files changed, 12 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 038cba9e5..8d6a41b9f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -71,13 +71,16 @@ sub index : Path : Args(0) {
}
my @unsent = $c->cobrand->problems->search( {
- state => [ FixMyStreet::DB::Result::Problem::open_states() ],
+ 'me.state' => [ FixMyStreet::DB::Result::Problem::open_states() ],
whensent => undef,
bodies_str => { '!=', undef },
# Ignore very recent ones that probably just haven't been sent yet
confirmed => { '<', \"current_timestamp - '5 minutes'::interval" },
},
{
+ '+columns' => ['user.email'],
+ prefetch => 'contact',
+ join => 'user',
order_by => 'confirmed',
} )->all;
$c->stash->{unsent_reports} = \@unsent;
@@ -301,7 +304,14 @@ sub add_flags : Private {
sub flagged : Path('flagged') : Args(0) {
my ( $self, $c ) = @_;
- my $problems = $c->cobrand->problems->search( { flagged => 1 } );
+ my $problems = $c->cobrand->problems->search(
+ { 'me.flagged' => 1 },
+ {
+ '+columns' => ['user.email'],
+ join => 'user',
+ prefetch => 'contact',
+ }
+ );
# pass in as array ref as using same template as search_reports
# which has to use an array ref for sql quoting reasons