aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 11:17:53 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 11:17:53 +0100
commitf19221e0cd17d02159c01a6ddc2c55b28ce4d730 (patch)
tree053a6758f068550d12854dc7ff1ce59e81a684a9
parent36790b4c14248f374e333dec805509e0b4d45ff4 (diff)
Remove specific files rather than glob.
This should improve performance when there are a lot of cached photos.
-rw-r--r--perllib/FixMyStreet/App/Model/PhotoSet.pm19
1 files changed, 15 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm
index 030dbd5be..1c8a86e3a 100644
--- a/perllib/FixMyStreet/App/Model/PhotoSet.pm
+++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm
@@ -254,14 +254,25 @@ sub get_image_data {
sub delete_cached {
my ($self) = @_;
my $object = $self->object or return;
+ my $id = $object->id or return;
my @dirs = ('web', 'photo');
push @dirs, 'c' if ref $object eq 'FixMyStreet::DB::Result::Comment';
- unlink glob FixMyStreet->path_to(
- @dirs,
- $object->id . '.*'
- );
+ # Old files without an index number; will always be .jpeg
+ foreach my $size ("", ".fp", ".tn", ".full") {
+ unlink FixMyStreet->path_to(@dirs, "$id$size.jpeg");
+ }
+
+ # New files with index number
+ my @images = $self->all_ids;
+ foreach (map [ $_, $images[$_] ], 0 .. $#images) {
+ my ($i, $file) = @$_;
+ my ($fileid, $type) = split /\./, $file;
+ foreach my $size ("", ".fp", ".tn", ".full") {
+ unlink FixMyStreet->path_to(@dirs, "$id.$i$size.$type");
+ }
+ }
}
sub remove_images {