diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-01-25 12:45:09 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-01-25 15:51:19 +0000 |
commit | 09ac8e89c3caab877454ab66665410f82f90f945 (patch) | |
tree | 52ddf5e5838e397fbfa973843de2d7fc07320cdd /perllib/FixMyStreet/App/Controller/Reports.pm | |
parent | 221b5bd0e7715bd3f8f7d324bf97937edbf5c13d (diff) |
Stop changing DateTimes to epochs and back.
Also revert cursor handling of Reports.pm; the DateTime inflation
appears to be a slowdown, and we were doing that anyway, and this way
makes things simpler in general. Will have a watch out for any
performance issue, but hopefully it should be fine.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f4093ef21..85a6e7c4d 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -372,53 +372,32 @@ sub load_and_group_problems : Private { my $problems = $c->cobrand->problems->search( $where, { - columns => [ - 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, - #{ age => { extract => "epoch from current_timestamp-confirmed" } }, - { created => { extract => 'epoch from created' } }, - { confirmed => { extract => 'epoch from confirmed' } }, - { whensent => { extract => 'epoch from whensent' } }, - { lastupdate => { extract => 'epoch from lastupdate' } }, - 'photo', 'extra', - ], order_by => { -desc => 'lastupdate' }, rows => $c->cobrand->reports_per_page, } )->page( $page ); $c->stash->{pager} = $problems->pager; - $problems = $problems->cursor; # Raw DB cursor for speed my ( %problems, @pins ); - my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'created', 'confirmed', 'whensent', 'lastupdate', 'photo', 'extra' ); - while ( my @problem = $problems->next ) { - my %problem = zip @cols, @problem; - $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; - if ($problem{extra} && $c->cobrand->moniker eq 'zurich') { # Inflate - utf8::encode($problem{extra}) if utf8::is_utf8($problem{extra}); - $problem{extra} = RABX::unserialise($problem{extra}); - } - $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); + while ( my $problem = $problems->next ) { + $c->log->debug( $problem->cobrand . ', cobrand is ' . $c->cobrand->moniker ); if ( !$c->stash->{body}->id ) { # An external_body entry - add_row( \%problem, 0, \%problems, \@pins ); + add_row( $problem, 0, \%problems, \@pins ); next; } - if ( !$problem{bodies_str} ) { + if ( !$problem->bodies_str ) { # Problem was not sent to any body, add to all possible areas XXX - $problem{bodies} = 0; - while ($problem{areas} =~ /,(\d+)(?=,)/g) { - add_row( \%problem, $1, \%problems, \@pins ); + while ($problem->areas =~ /,(\d+)(?=,)/g) { + add_row( $problem, $1, \%problems, \@pins ); } } else { # Add to bodies it was sent to # XXX Assumes body ID matches "council ID" - (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); - $problem{bodies} = scalar @bodies; - foreach ( @bodies ) { + my $bodies = $problem->bodies_str_ids; + foreach ( @$bodies ) { next if $_ != $c->stash->{body}->id; - add_row( \%problem, $_, \%problems, \@pins ); + add_row( $problem, $_, \%problems, \@pins ); } } } @@ -452,11 +431,11 @@ sub add_row { my ( $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; push @$pins, { - latitude => $problem->{latitude}, - longitude => $problem->{longitude}, - colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', - id => $problem->{id}, - title => $problem->{title}, + latitude => $problem->latitude, + longitude => $problem->longitude, + colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->state} ? 'green' : 'red', + id => $problem->id, + title => $problem->title, }; } |