aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm35
-rw-r--r--perllib/Memcached.pm17
3 files changed, 20 insertions, 33 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d973a8c8..519592b7f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
- Improved cursor/display of the new report pin. #2038
- Asset layers can be attached to more than one category each. #2049
- Cobrands hook to remove phone number field. #2049
+ - Check recent reports for any hidden since cached. #2053
- Bugfixes:
- Stop asset layers obscuring marker layer. #1999
- Don't delete hidden field values when inspecting reports. #1999
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index ebc6e6c1b..e262cb63e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -132,34 +132,25 @@ sub _recent {
};
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!
- $key .= ":$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;
- } ];
- $new = 1;
- }
+ if (defined $lat) { # No caching
+ $attrs->{bind} = [ $lat, $lon, $dist ];
+ $attrs->{join} = 'nearby';
+ $probs = [ mySociety::Locale::in_gb_locale {
+ $rs->search( $query, $attrs )->all;
+ } ];
} else {
$probs = Memcached::get($key);
- unless ($probs) {
+ if ($probs) {
+ # Need to reattach schema so that confirmed column gets reinflated.
+ $probs->[0]->result_source->schema( $rs->result_source->schema ) if $probs->[0];
+ # Catch any cached ones since hidden
+ $probs = [ grep { ! $_->is_hidden } @$probs ];
+ } else {
$probs = [ $rs->search( $query, $attrs )->all ];
- $new = 1;
+ Memcached::set($key, $probs, 3600);
}
}
- 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;
}
diff --git a/perllib/Memcached.pm b/perllib/Memcached.pm
index b612dd5ac..150594a01 100644
--- a/perllib/Memcached.pm
+++ b/perllib/Memcached.pm
@@ -4,39 +4,34 @@
#
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: Memcached.pm,v 1.3 2008-10-10 15:57:28 matthew Exp $
-#
package Memcached;
use strict;
+use warnings;
use Cache::Memcached;
my ($memcache, $namespace);
sub set_namespace {
$namespace = shift;
- $namespace = 'fms' if $namespace eq 'fixmystreet';
}
-sub cache_connect {
- $memcache = new Cache::Memcached {
+sub instance {
+ return $memcache //= Cache::Memcached->new({
'servers' => [ '127.0.0.1:11211' ],
'namespace' => $namespace,
'debug' => 0,
'compress_threshold' => 10_000,
- };
+ });
}
sub get {
- cache_connect() unless $memcache;
- $memcache->get(@_);
+ instance->get(@_);
}
sub set {
- cache_connect() unless $memcache;
- $memcache->set(@_);
+ instance->set(@_);
}
1;