use cache data we already have to check if a thumbnail of specific size is cached

This commit is contained in:
Robin Appelman 2015-07-17 13:25:09 +02:00
parent 52d4495793
commit 9925ff33f1
1 changed files with 24 additions and 1 deletions

View File

@ -479,7 +479,7 @@ class Preview {
$preview = $this->buildCachePath($fileId, $previewWidth, $previewHeight);
// This checks if we have a preview of those exact dimensions in the cache
if ($this->userView->file_exists($preview)) {
if ($this->thumbnailSizeExists($allThumbnails, $previewWidth, $previewHeight)) {
return $preview;
}
@ -524,6 +524,29 @@ class Preview {
return [$maxPreviewX, $maxPreviewY];
}
/**
* Check if a specific thumbnail size is cached
*
* @param FileInfo[] $allThumbnails the list of all our cached thumbnails
* @param int $width
* @param int $height
* @return bool
*/
private function thumbnailSizeExists($allThumbnails, $width, $height) {
foreach ($allThumbnails as $thumbnail) {
$name = $thumbnail['name'];
if (strpos($name, 'max')) {
list($cachedWidth, $cachedHeight) = $this->getDimensionsFromFilename($name);
if ($cachedWidth === $width && $cachedHeight === $height) {
return true;
}
}
}
return false;
}
/**
* Determines the size of the preview we should be looking for in the cache
*