Skip to content
Snippets Groups Projects
Commit 8282cfff authored by Robin Appelman's avatar Robin Appelman
Browse files

Cache the fileinfo in OC\Preview

parent 832f6e4e
Branches
No related tags found
No related merge requests found
......@@ -52,6 +52,11 @@ class Preview {
static private $providers = array();
static private $registeredProviders = array();
/**
* @var \OCP\Files\FileInfo
*/
protected $info;
/**
* @brief check if thumbnail or bigger version of thumbnail of file is cached
* @param string $user userid - if no user is given, OC_User::getUser will be used
......@@ -160,6 +165,13 @@ class Preview {
return $this->configMaxY;
}
protected function getFileInfo() {
if (!$this->info) {
$this->info = $this->fileView->getFileInfo($this->file);
}
return $this->info;
}
/**
* @brief set the path of the file you want a thumbnail from
* @param string $file
......@@ -167,8 +179,9 @@ class Preview {
*/
public function setFile($file) {
$this->file = $file;
$this->info = null;
if ($file !== '') {
$this->mimetype = $this->fileView->getMimeType($this->file);
$this->mimetype = $this->getFileInfo()->getMimetype();
}
return $this;
}
......@@ -260,12 +273,11 @@ class Preview {
public function deletePreview() {
$file = $this->getFile();
$fileInfo = $this->fileView->getFileInfo($file);
$fileId = $fileInfo['fileid'];
$fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo->getId();
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png';
$this->userView->unlink($previewPath);
return !$this->userView->file_exists($previewPath);
return $this->userView->unlink($previewPath);
}
/**
......@@ -275,13 +287,12 @@ class Preview {
public function deleteAllPreviews() {
$file = $this->getFile();
$fileInfo = $this->fileView->getFileInfo($file);
$fileId = $fileInfo['fileid'];
$fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo->getId();
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
$this->userView->deleteAll($previewPath);
$this->userView->rmdir($previewPath);
return !$this->userView->is_dir($previewPath);
return $this->userView->rmdir($previewPath);
}
/**
......@@ -297,8 +308,8 @@ class Preview {
$scalingUp = $this->getScalingUp();
$maxScaleFactor = $this->getMaxScaleFactor();
$fileInfo = $this->fileView->getFileInfo($file);
$fileId = $fileInfo['fileid'];
$fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo->getId();
if (is_null($fileId)) {
return false;
......@@ -386,8 +397,8 @@ class Preview {
$maxY = $this->getMaxY();
$scalingUp = $this->getScalingUp();
$fileInfo = $this->fileView->getFileInfo($file);
$fileId = $fileInfo['fileid'];
$fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo->getId();
$cached = $this->isCached();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment