Optimize thumbnail check logic

This commit is contained in:
Kijin Sung 2020-10-01 17:03:42 +09:00
parent 4102c4bda2
commit 9d0e808514
2 changed files with 30 additions and 36 deletions

View file

@ -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("!<img!is", $this->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("!<img!is", $this->get('content')))
{
return;
}
// Create lockfile to prevent race condition
FileHandler::writeFile($thumbnail_lockfile, '', 'w');