aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm13
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm53
4 files changed, 33 insertions, 46 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 958194eb8..195fe4019 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -132,21 +132,12 @@ sub confirm {
=head2 get_photo_params
Returns a hashref of details of any attached photo for use in templates.
-Hashref contains height, width and url keys.
=cut
sub get_photo_params {
my $self = shift;
-
- return {} unless $self->photo;
-
- my $photo = {};
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$self->photo );
- $photo->{url} = '/photo?c=' . $self->id;
-
- return $photo;
+ return FixMyStreet::App::get_photo_params($self, 'c');
}
=head2 meta_problem_state
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 7ceabf1da..ce7488703 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -329,7 +329,7 @@ sub check_for_errors {
|| $self->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i )
{
$errors{name} = _(
-'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box'
+'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below'
);
}
@@ -400,21 +400,12 @@ sub url {
=head2 get_photo_params
Returns a hashref of details of any attached photo for use in templates.
-Hashref contains height, width and url keys.
=cut
sub get_photo_params {
my $self = shift;
-
- return {} unless $self->photo;
-
- my $photo = {};
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$self->photo );
- $photo->{url} = '/photo?id=' . $self->id;
-
- return $photo;
+ return FixMyStreet::App::get_photo_params($self, 'id');
}
=head2 is_open
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 04089096e..83fc85a88 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -24,7 +24,7 @@ sub nearby {
columns => [
'problem.id', 'problem.title', 'problem.latitude',
'problem.longitude', 'distance', 'problem.state',
- 'problem.confirmed'
+ 'problem.confirmed', { 'problem.photo' => 'problem.photo is not null' },
],
bind => [ $mid_lat, $mid_lon, $dist ],
order_by => [ 'distance', { -desc => 'created' } ],
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 59227fce8..3557e77c7 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -62,39 +62,36 @@ sub recent_new {
sub recent {
my ( $rs ) = @_;
- my $key = "recent:$site_key";
- my $result = Memcached::get($key);
- if ( $result ) {
- # Need to reattach schema so that confirmed column gets reinflated.
- $result->[0]->result_source->schema( $rs->result_source->schema ) if $result->[0];
- } else {
- $result = [ $rs->search( {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
- }, {
- columns => [ 'id', 'title', 'confirmed' ],
- order_by => { -desc => 'confirmed' },
- rows => 5,
- } )->all ];
- Memcached::set($key, $result, 3600);
- }
- return $result;
+ return _recent( $rs, 5 );
}
sub recent_photos {
my ( $rs, $num, $lat, $lon, $dist ) = @_;
- my $probs;
+ return _recent( $rs, $num, $lat, $lon, $dist, 1);
+}
+
+sub _recent {
+ my ( $rs, $num, $lat, $lon, $dist, $photos ) = @_;
+
+ my $key = $photos ? 'recent_photos' : 'recent';
+ $key .= ":$site_key:$num";
+
my $query = {
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
- photo => { '!=', undef },
};
+ $query->{photo} = { '!=', undef } if $photos;
+
my $attrs = {
- columns => [ 'id', 'title' ],
+ columns => [ 'id', 'title', 'confirmed' ],
order_by => { -desc => 'confirmed' },
rows => $num,
};
+
+ my $probs;
+ my $new = 0;
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";
+ $key .= ":$lat:$lon:$dist2";
$probs = Memcached::get($key);
unless ($probs) {
$attrs->{bind} = [ $lat, $lon, $dist ];
@@ -102,16 +99,23 @@ sub recent_photos {
$probs = [ mySociety::Locale::in_gb_locale {
$rs->search( $query, $attrs )->all;
} ];
- Memcached::set($key, $probs, 3600);
+ $new = 1;
}
} 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);
+ $new = 1;
}
}
+
+ if ( $new ) {
+ Memcached::set($key, $probs, 3600);
+ } else {
+ # Need to reattach schema so that confirmed column gets reinflated.
+ $probs->[0]->result_source->schema( $rs->result_source->schema ) if $probs->[0];
+ }
+
return $probs;
}
@@ -122,7 +126,8 @@ sub around_map {
my $attr = {
order_by => { -desc => 'created' },
columns => [
- 'id', 'title' ,'latitude', 'longitude', 'state', 'confirmed'
+ 'id', 'title', 'latitude', 'longitude', 'state', 'confirmed',
+ { photo => 'photo is not null' },
],
};
$attr->{rows} = $limit if $limit;