If `TrivGal::Image::scale' can't find an existing scaled image, then by
default it just returns immediately with a `?scale=...' link. The code
acting on this parameter now passes an additional FORCEP argument to
`TrivGal::Image::scale' to get it to actually generate the scaled
version. Once the scaled version exists, `TrivGal::Image::scale'
returns a direct link to it rather than the `?scale=...' link, which
saves a redirect round trip.
This has two main effects.
* Firstly, and most importantly, it allows the main HTML to be served
up immediately, without waiting for the (rather time-consuming)
image scaling to happen; and it also allows the scaling to happen
with a certain amount of parallelism.
* Secondly, it also isolates failures (e.g., due to exceeding memory
limits) to individual images.
- sub scale ($$) {
- my ($me, $scale) = @_;
+ sub scale ($$;$) {
+ my ($me, $scale, $forcep) = @_;
my $m = HTML::Mason::Request->instance;
my $path = $me->{path};
my $m = HTML::Mason::Request->instance;
my $path = $me->{path};
$m->interp->apply_escapes("$CACHEURL/scale.$sz/$path", "u");
my $st = stat $thumb;
if (defined $st && $st->mtime > $me->{mtime}) { return $thumburl; }
$m->interp->apply_escapes("$CACHEURL/scale.$sz/$path", "u");
my $st = stat $thumb;
if (defined $st && $st->mtime > $me->{mtime}) { return $thumburl; }
+ return
+ $m->interp->apply_escapes("$SCRIPTURL/$path", "u") . "?scale=$scale"
+ unless $forcep;
my ($dir, $base, $ext) = TrivGal::split_path $thumb;
my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
my ($dir, $base, $ext) = TrivGal::split_path $thumb;
my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
if (defined $scale) {
my $img = TrivGal::Image->new($path);
if (defined $scale) {
my $img = TrivGal::Image->new($path);
- $m->redirect($img->scale($scale));
+ $m->redirect($img->scale($scale, 1));
}
my $real = join_paths $IMGROOT, $path;
}
my $real = join_paths $IMGROOT, $path;