aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/Cobrand/Barnet.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Southampton.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm8
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm39
5 files changed, 48 insertions, 5 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 {