aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/My.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/My.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/My.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm14
1 files changed, 9 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 3328caac0..316fe08b8 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -135,13 +135,14 @@ sub get_problems : Private {
my $problems = [];
my $states = $c->stash->{filter_problem_states};
+ my $table = $c->action eq 'my/planned' ? 'report' : 'me';
my $params = {
- state => [ keys %$states ],
+ "$table.state" => [ keys %$states ],
};
my $categories = [ $c->get_param_list('filter_category', 1) ];
if ( @$categories ) {
- $params->{category} = $categories;
+ $params->{"$table.category"} = $categories;
$c->stash->{filter_category} = { map { $_ => 1 } @$categories };
}
@@ -149,6 +150,7 @@ sub get_problems : Private {
$rows = 5000 if $c->stash->{sort_key} eq 'shortlist'; # Want all reports
my $rs = $c->stash->{problems_rs}->search( $params, {
+ prefetch => 'contact',
order_by => $c->stash->{sort_order},
rows => $rows,
} )->include_comment_counts->page( $p_page );
@@ -186,12 +188,14 @@ sub get_updates : Private {
sub setup_page_data : Private {
my ($self, $c) = @_;
+ my $table = $c->action eq 'my/planned' ? 'report' : 'me';
my @categories = $c->stash->{problems_rs}->search({
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
+ "$table.state" => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
- columns => [ 'category', 'bodies_str', 'extra' ],
+ join => 'contact',
+ columns => [ "$table.category", 'contact.extra', 'contact.category' ],
distinct => 1,
- order_by => [ 'category' ],
+ order_by => [ "$table.category" ],
} )->all;
$c->stash->{filter_categories} = \@categories;
$c->forward('/report/stash_category_groups', [ \@categories ]) if $c->cobrand->enable_category_groups;