From 3c6b09110ac33fd58f768d7134093f0e560d5ebd Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 7 Jul 2019 14:25:28 +0100 Subject: [PATCH] Cache multiple flexihashes otherwise get_thumb / get_image / get_thumb / get_image / ... will have 100% cache miss rate --- core/imageboard/image.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 05ad5db8..fa66f0fd 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -812,16 +812,17 @@ class Image $tmpl = $plte->link; } - static $flexihash = null; - static $fh_last_opts = null; + static $flexihashes = []; $matches = []; if (preg_match("/(.*){(.*)}(.*)/", $tmpl, $matches)) { $pre = $matches[1]; $opts = $matches[2]; $post = $matches[3]; - if ($opts != $fh_last_opts) { - $fh_last_opts = $opts; + if(isset($flexihashes[$opts])) { + $flexihash = $flexihashes[$opts]; + } + else { $flexihash = new Flexihash\Flexihash(); foreach (explode(",", $opts) as $opt) { $parts = explode("=", $opt); @@ -837,6 +838,7 @@ class Image } $flexihash->addTarget($opt_val, $opt_weight); } + $flexihashes[$opts] = $flexihash; } // $choice = $flexihash->lookup($pre.$post);