From c11f599687ae12a5c2b65e06f7984ac0e107c3de Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Tue, 3 Nov 2020 11:10:13 +0100 Subject: [PATCH] refs #18290 [finc] add caching for fallback covers * also removed redundant array-check in Router --- module/finc/src/finc/Cover/Loader.php | 19 +++++++++++++++++++ module/finc/src/finc/Cover/Router.php | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/module/finc/src/finc/Cover/Loader.php b/module/finc/src/finc/Cover/Loader.php index b67ff8ee24e..672c93a651b 100644 --- a/module/finc/src/finc/Cover/Loader.php +++ b/module/finc/src/finc/Cover/Loader.php @@ -41,6 +41,8 @@ namespace finc\Cover; */ class Loader extends \VuFind\Cover\Loader { + const EMPTY_IMAGE_CONTENT = 'nothing here'; + /** * Flag denoting the last loaded image was a FailImage * @@ -57,9 +59,26 @@ class Loader extends \VuFind\Cover\Loader public function loadUnavailable() { $this->hasLoadedUnavailable = true; + file_put_contents($this->localFile,self::EMPTY_IMAGE_CONTENT); return parent::loadUnavailable(); } + public function loadImage($settings = []) + { + parent::loadImage($settings); + if ($this->image === self::EMPTY_IMAGE_CONTENT) { + $this->hasLoadedUnavailable = true; + } + } + + public function getImage() + { + if ($this->image === self::EMPTY_IMAGE_CONTENT) { + $this->hasLoadedUnavailable = true; + } + return parent::getImage(); + } + /** * Returns true if the last loaded image was the FailImage * diff --git a/module/finc/src/finc/Cover/Router.php b/module/finc/src/finc/Cover/Router.php index 8a758f27c9f..5cc789f6855 100644 --- a/module/finc/src/finc/Cover/Router.php +++ b/module/finc/src/finc/Cover/Router.php @@ -98,10 +98,8 @@ class Router implements \Zend\Log\LoggerAwareInterface if (!$resolveDynamic) { return null; } - $settings = is_array($thumb) ? array_merge($thumb, ['size' => $size]) - : ['size' => $size]; if ($testLoadImage) { - $this->coverLoader->loadImage($settings); + $this->coverLoader->loadImage(array_merge($thumb, ['size' => $size])); if ($this->coverLoader->hasLoadedUnavailable()) { return false; } -- GitLab