diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-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 | 39 | ||||
-rw-r--r-- | perllib/Problems.pm | 78 |
6 files changed, 48 insertions, 83 deletions
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..72c279076 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 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..0ca8d1127 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -51,18 +51,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 { diff --git a/perllib/Problems.pm b/perllib/Problems.pm index 5f38a12c4..1f3eaf7b9 100644 --- a/perllib/Problems.pm +++ b/perllib/Problems.pm @@ -39,84 +39,6 @@ sub number_comments { return $result; } -# Front page recent lists - -sub recent_photos { - my ($num, $lat, $lon, $dist) = @_; - my $probs; - 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) { - $probs = mySociety::Locale::in_gb_locale { - select_all("select id, title - from problem_find_nearby(?, ?, ?) as nearby, problem - where nearby.problem_id = problem.id - and state in ('confirmed', 'fixed') and photo is not null - $site_restriction - order by confirmed desc limit $num", $lat, $lon, $dist); - }; - Memcached::set($key, $probs, 3600); - } - } else { - my $key = "recent_photos:$site_key:$num"; - $probs = Memcached::get($key); - unless ($probs) { - $probs = select_all("select id, title from problem - where state in ('confirmed', 'fixed') and photo is not null - $site_restriction - order by confirmed desc limit $num"); - Memcached::set($key, $probs, 3600); - } - } - my $out = ''; - foreach (@$probs) { - my $title = ent($_->{title}); - $out .= '<a href="/report/' . $_->{id} . - '"><img border="0" height="100" src="/photo?tn=1;id=' . $_->{id} . - '" alt="' . $title . '" title="' . $title . '"></a>'; - } - return $out; -} - -# Fetch an individual problem - -# Report functions - -=item council_problems WARD COUNCIL - -Returns a list of problems for a summary page. If WARD or COUNCIL area ids are given, -will only return problems for that area. Uses any site restriction defined by the -cobrand. - -=cut - -sub council_problems { - my ($ward, $one_council) = @_; - my @params; - my $where_extra = ''; - if ($ward) { - push @params, $ward; - $where_extra = "and areas like '%,'||?||',%'"; - } elsif ($one_council) { - push @params, $one_council; - $where_extra = "and areas like '%,'||?||',%'"; - } - my $current_timestamp = current_timestamp(); - my $problems = select_all( - "select id, title, detail, council, state, areas, - extract(epoch from $current_timestamp-lastupdate) as duration, - extract(epoch from $current_timestamp-confirmed) as age - from problem - where state in ('confirmed', 'fixed') - $where_extra - $site_restriction - order by id desc - ", @params); - return $problems; -} - # Admin view functions =item problem_search SEARCH |