]> git.donarmstrong.com Git - debbugs.git/commit
Libravatar: Refactor cache handling to avoid unncessary stat
authorNiels Thykier <niels@thykier.net>
Wed, 3 Aug 2016 20:51:20 +0000 (20:51 +0000)
committerNiels Thykier <niels@thykier.net>
Thu, 4 Aug 2016 18:57:28 +0000 (18:57 +0000)
commit1795f7f2a672ee6482240c4037b0bccd53117a2c
treec484003da3b878a75a4bbcb69dc38c6f9d7c360a
parent2da5c58430ad99f69d913865850c002af6882181
Libravatar: Refactor cache handling to avoid unncessary stat

The basic pattern of the code we are dealing with is:

  my $path = cache_location(...);
  if (valid_cache($path)) {
    ...;
  }

With cache_location possibly doing a stat() of $path and valid_cache
doing at least one stat() as well.  Rewrite it so that cache_location
always stats and checks the cache (since we always need it).  This way
we can now guarantee this flow requires at *most* 3 stats rather than
5.

The replacement for the above code becomes:

  my ($path, $is_valid) = cache_location(...);
  if ($is_valid) {
     ...;
  }

Signed-off-by: Niels Thykier <niels@thykier.net>
Debbugs/Libravatar.pm
cgi/libravatar.cgi