From e8761848613fdc15d10469580019c33587d18033 Mon Sep 17 00:00:00 2001 From: glubsy Date: Mon, 25 Jan 2021 21:42:41 +0000 Subject: [PATCH] Reduce superfluous computations Only compute thumbnail configured dimensions on thumbnail API requests. --- src/_h5ai/private/php/core/class-context.php | 7 +++---- src/_h5ai/private/php/ext/class-thumb.php | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/_h5ai/private/php/core/class-context.php b/src/_h5ai/private/php/core/class-context.php index 64c9b72c..071b56af 100644 --- a/src/_h5ai/private/php/core/class-context.php +++ b/src/_h5ai/private/php/core/class-context.php @@ -23,9 +23,6 @@ class Context { $this->options = Json::load($this->setup->get('CONF_PATH') . '/options.json'); - $this->thumbnail_height = $this->options['thumbnails']['size'] ?? 240; - $this->thumbnail_width = floor($this->thumbnail_height * (4 / 3)); - $this->passhash = $this->query_option('passhash', ''); $this->options['hasCustomPasshash'] = strcasecmp($this->passhash, Context::$DEFAULT_PASSHASH) !== 0; unset($this->options['passhash']); @@ -250,10 +247,12 @@ class Context { public function get_thumbs($requests) { $hrefs = []; + $height = $this->options['thumbnails']['size'] ?? 240; + $width = floor($this->thumbnail_height * (4 / 3)); foreach ($requests as $req) { $thumb = new Thumb($this); - $hrefs[] = $thumb->thumb($req['type'], $req['href']); + $hrefs[] = $thumb->thumb($req['type'], $req['href'], $width, $height); } return $hrefs; diff --git a/src/_h5ai/private/php/ext/class-thumb.php b/src/_h5ai/private/php/ext/class-thumb.php index 0f9823fb..d52d3e85 100644 --- a/src/_h5ai/private/php/ext/class-thumb.php +++ b/src/_h5ai/private/php/ext/class-thumb.php @@ -23,7 +23,7 @@ class Thumb { } } - public function thumb($type, $source_href) { + public function thumb($type, $source_href, $width, $height) { $source_path = $this->context->to_path($source_href); if (!file_exists($source_path) || Util::starts_with($source_path, $this->setup->get('CACHE_PUB_PATH'))) { return null; @@ -46,7 +46,7 @@ class Thumb { } } - return $this->thumb_href($capture_path, $this->context->thumbnail_width, $this->context->thumbnail_height); + return $this->thumb_href($capture_path, $width, $height); } private function thumb_href($source_path, $width, $height) {