diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 53 |
8 files changed, 73 insertions, 40 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index bd7d415e7..047de7691 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -63,16 +63,8 @@ sub determine_contact_type : Private { $update_id = undef unless $update_id && $update_id =~ /^[1-9]\d*$/; if ($id) { - my $problem = $c->cobrand->problems->find( - { id => $id }, - { - 'select' => [ - 'title', 'detail', 'name', - 'anonymous', 'id', - 'user_id', 'confirmed', - ] - } - ); + + $c->forward( '/report/load_problem_or_display_error', [ $id ] ); if ($update_id) { my $update = $c->model('DB::Comment')->find( @@ -81,9 +73,6 @@ sub determine_contact_type : Private { $c->stash->{update} = $update; } - elsif ($problem) { - $c->stash->{problem} = $problem; - } } return 1; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 0fe1834e7..497ec784a 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -52,6 +52,7 @@ sub display : Path('') : Args(1) { } $c->forward('load_problem_or_display_error', [ $id ] ); + $c->forward( 'load_updates' ); $c->forward( 'format_problem_for_display' ); } @@ -76,9 +77,14 @@ sub load_problem_or_display_error : Private { } $c->stash->{problem} = $problem; + return 1; +} + +sub load_updates : Private { + my ( $self, $c ) = @_; my $updates = $c->model('DB::Comment')->search( - { problem_id => $problem->id, state => 'confirmed' }, + { problem_id => $c->stash->{problem}->id, state => 'confirmed' }, { order_by => 'confirmed' } ); diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2ca9245ad..2f1d88d08 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -24,7 +24,7 @@ sub report_update : Path : Args(0) { $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ) unless $c->req->param('id'); - $c->forward('setup_page') + $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ) && $c->forward('process_user') && $c->forward('process_update') && $c->forward('/report/new/process_photo') @@ -89,25 +89,6 @@ sub display_confirmation : Private { return 1; } -=head2 setup_page - -Setup things we need for later. - -=cut - -sub setup_page : Private { - my ( $self, $c ) = @_; - - my $problem = - $c->cobrand->problems->find( { id => $c->req->param('id') } ); - - return unless $problem; - - $c->stash->{problem} = $problem; - - return 1; -} - =head2 process_user Load user from the database or prepare a new one. diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 460bd3be9..e7bc67c5c 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -82,7 +82,7 @@ sub disambiguate_location { sub recent_photos { my ( $self, $num, $lat, $lon, $dist ) = @_; $num = 2 if $num == 3; - return Problems::recent_photos( $num, $lat, $lon, $dist ); + return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } sub tilma_mid_point { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 949d875a3..fd03f235f 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -219,7 +219,7 @@ EASTING and NORTHING. sub recent_photos { my $self = shift; - return Problems::recent_photos(@_); + return $self->problems->recent_photos(@_); } =head2 recent @@ -258,7 +258,7 @@ sub front_stats_data { my $shorter_recency = '3 days'; my $fixed = $self->problems->recent_fixed(); - my $updates = Problems::number_comments(); + my $updates = $self->problems->number_comments(); my $new = $self->problems->recent_new( $recency ); if ( $new > $fixed && $self->shorten_recency_if_new_greater_than_fixed ) { diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index 99484181a..d70d818be 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -81,7 +81,7 @@ sub disambiguate_location { sub recent_photos { my ($self, $num, $lat, $lon, $dist) = @_; $num = 2 if $num == 3; - return Problems::recent_photos( $num, $lat, $lon, $dist ); + return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } sub tilma_mid_point { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index f1665ccba..ab05c3157 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -103,6 +103,14 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-05-24 15:32:43 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U3aYCRwE4etekKaHdhEkIw +# Add fake relationship to stored procedure table +__PACKAGE__->has_many( + "nearby", + "FixMyStreet::DB::Result::Nearby", + { "foreign.problem_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + use DateTime::TimeZone; use Image::Size; use Moose; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index ea146cd54..1f06acf5a 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -29,6 +29,20 @@ sub recent_fixed { return $result; } +sub number_comments { + my $rs = shift; + my $key = "number_comments:$site_key"; + my $result = Memcached::get($key); + unless ($result) { + $result = $rs->search( + { 'comments.state' => 'confirmed' }, + { join => 'comments' } + )->count; + Memcached::set($key, $result, 3600); + } + return $result; +} + sub recent_new { my ( $rs, $interval ) = @_; (my $key = $interval) =~ s/\s+//g; @@ -51,18 +65,53 @@ sub recent { my $key = "recent:$site_key"; my $result = Memcached::get($key); unless ($result) { - $result = $rs->search( { + $result = [ $rs->search( { state => [ 'confirmed', 'fixed' ] }, { columns => [ 'id', 'title' ], order_by => { -desc => 'confirmed' }, rows => 5, - } )->count; + } )->all ]; Memcached::set($key, $result, 3600); } return $result; } +sub recent_photos { + my ( $rs, $num, $lat, $lon, $dist ) = @_; + my $probs; + my $query = { + state => [ 'confirmed', 'fixed' ], + photo => { '!=', undef }, + }; + my $attrs = { + columns => [ 'id', 'title' ], + order_by => { -desc => 'confirmed' }, + rows => $num, + }; + if (defined $lat) { + my $dist2 = $dist; # Create a copy of the variable to stop it being stringified into a locale in the next line! + my $key = "recent_photos:$site_key:$num:$lat:$lon:$dist2"; + $probs = Memcached::get($key); + unless ($probs) { + $attrs->{bind} = [ $lat, $lon, $dist ]; + $attrs->{join} = 'nearby'; + $probs = [ mySociety::Locale::in_gb_locale { + $rs->search( $query, $attrs )->all; + } ]; + Memcached::set($key, $probs, 3600); + } + } else { + my $key = "recent_photos:$site_key:$num"; + $probs = Memcached::get($key); + unless ($probs) { + $probs = [ $rs->search( $query, $attrs )->all ]; + Memcached::set($key, $probs, 3600); + } + } + return $probs; +} + # Problems around a location sub around_map { |