From 591c90a2ac4ea419a062bf19fffb0831d06786df Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 9 Oct 2015 15:29:05 +0100 Subject: Speed up admin front page. * Don't show a categories summary unless asked via a link * Don't needlessly join in questionnaire/update summaries * Switch count(distinct()) to a subselect as it turns out select count(*) from (select distinct(user_id) from problem) temp; is a lot quicker than select count(distinct(user_id)) from problem; --- perllib/FixMyStreet/DB/ResultSet/Comment.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Comment.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm index 270501efc..1b6afb819 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -32,15 +32,16 @@ sub timeline { sub summary_count { my ( $rs, $body_restriction ) = @_; - return $rs->to_body($body_restriction)->search( - undef, - { - group_by => ['me.state'], - select => [ 'me.state', { count => 'me.id' } ], - as => [qw/state state_count/], - join => 'problem' - } - ); + my $params = { + group_by => ['me.state'], + select => [ 'me.state', { count => 'me.id' } ], + as => [qw/state state_count/], + }; + if ($body_restriction) { + $rs = $rs->to_body($body_restriction); + $params->{join} = 'problem'; + } + return $rs->search(undef, $params); } 1; -- cgit v1.2.3