From 9d0e808514ac3c78127d74326386eb51e5e79902 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Oct 2020 17:03:42 +0900 Subject: [PATCH] Optimize thumbnail check logic --- modules/comment/comment.item.php | 25 ++++++------------ modules/document/document.item.php | 41 ++++++++++++++++-------------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index 71138e7f4..993496c4f 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -635,17 +635,13 @@ class commentItem extends BaseObject function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // return false if no doc exists - if(!$this->comment_srl) + if(!$this->comment_srl || !$this->isAccessible()) { return; } // Get thumbnail type information from document module's configuration - $config = $GLOBALS['__document_config__']; - if(!$config) - { - $config = $GLOBALS['__document_config__'] = DocumentModel::getDocumentConfig(); - } + $config = DocumentModel::getDocumentConfig(); if ($config->thumbnail_target === 'none' || $config->thumbnail_type === 'none') { return; @@ -659,23 +655,12 @@ class commentItem extends BaseObject $config->thumbnail_quality = 75; } - if(!$this->isAccessible()) - { - return; - } - // If signiture height setting is omitted, create a square if(!$height) { $height = $width; } - // return false if neigher attached file nor image; - if(!$this->hasUploadedFiles() && !preg_match("!get('content'))) - { - return; - } - // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); @@ -695,6 +680,12 @@ class commentItem extends BaseObject } } + // return false if neigher attached file nor image; + if(!$this->get('uploaded_count') && !preg_match("!get('content'))) + { + return; + } + // Create lockfile to prevent race condition FileHandler::writeFile($thumbnail_lockfile, '', 'w'); diff --git a/modules/document/document.item.php b/modules/document/document.item.php index 52fe67b2a..ee9f073f0 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -1053,7 +1053,10 @@ class documentItem extends BaseObject function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // Return false if the document doesn't exist - if(!$this->document_srl) return; + if(!$this->document_srl || !$this->isAccessible()) + { + return; + } // Get thumbnail type information from document module's configuration $config = DocumentModel::getDocumentConfig(); @@ -1070,28 +1073,12 @@ class documentItem extends BaseObject $config->thumbnail_quality = 75; } - if(!$this->isAccessible()) - { - return; - } - // If not specify its height, create a square - if(!$height) $height = $width; - if($this->get('content')) + if(!$height) { - $content = $this->get('content'); - } - elseif($config->thumbnail_target !== 'attachment') - { - $args = new stdClass(); - $args->document_srl = $this->document_srl; - $output = executeQuery('document.getDocument', $args); - $content = $output->data->content; + $height = $width; } - // Return false if neither attachement nor image files in the document - if(!$this->get('uploaded_count') && !preg_match("!document_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); @@ -1110,6 +1097,22 @@ class documentItem extends BaseObject return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file)); } } + + // Get content if it does not exist. + if($this->get('content')) + { + $content = $this->get('content'); + } + elseif($config->thumbnail_target !== 'attachment') + { + $args = new stdClass(); + $args->document_srl = $this->document_srl; + $output = executeQuery('document.getDocument', $args); + $content = $output->data->content; + } + + // Return false if neither attachement nor image files in the document + if(!$this->get('uploaded_count') && !preg_match("!