diff options
author | Robin Appelman <robin@icewind.nl> | 2016-11-09 16:14:54 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-11-10 13:59:22 +0100 |
commit | cbcdf69dc218a9767b2682c0a1825f9f36e78266 (patch) | |
tree | 8693c71dbd7917795b2e8bbf735f6fc7f9c07f09 /lib/private/Files/FileInfo.php | |
parent | 742c215946555371b2ae1e855cefa65e5cc712a3 (diff) | |
download | nextcloud-server-cbcdf69dc218a9767b2682c0a1825f9f36e78266.tar.gz nextcloud-server-cbcdf69dc218a9767b2682c0a1825f9f36e78266.zip |
only query substorages to calculate the final mtime/size/etag lazily
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/FileInfo.php')
-rw-r--r-- | lib/private/Files/FileInfo.php | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index d463abfadcd..14a32ba8f76 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -31,6 +31,8 @@ namespace OC\Files; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage\IStorage; use OCP\IUser; class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { @@ -70,6 +72,13 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { private $childEtags = []; /** + * @var IMountPoint[] + */ + private $subMounts = []; + + private $subMountsUsed = false; + + /** * @param string|boolean $path * @param Storage\Storage $storage * @param string $internalPath @@ -103,6 +112,10 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { return $this->getType(); } else if ($offset === 'etag') { return $this->getEtag(); + } else if ($offset === 'size') { + return $this->getSize(); + } else if ($offset === 'mtime') { + return $this->getMTime(); } elseif ($offset === 'permissions') { return $this->getPermissions(); } elseif (isset($this->data[$offset])) { @@ -165,6 +178,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { * @return string */ public function getEtag() { + $this->updateEntryfromSubMounts(); if (count($this->childEtags) > 0) { $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); return md5($combinedEtag); @@ -177,6 +191,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { * @return int */ public function getSize() { + $this->updateEntryfromSubMounts(); return isset($this->data['size']) ? $this->data['size'] : 0; } @@ -184,6 +199,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { * @return int */ public function getMTime() { + $this->updateEntryfromSubMounts(); return $this->data['mtime']; } @@ -317,11 +333,33 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { } /** + * @param IMountPoint[] $mounts + */ + public function setSubMounts(array $mounts) { + $this->subMounts = $mounts; + } + + private function updateEntryfromSubMounts() { + if ($this->subMountsUsed) { + return; + } + $this->subMountsUsed = true; + foreach ($this->subMounts as $mount) { + $subStorage = $mount->getStorage(); + if ($subStorage) { + $subCache = $subStorage->getCache(''); + $rootEntry = $subCache->get(''); + $this->addSubEntry($rootEntry, $mount->getMountPoint()); + } + } + } + + /** * Add a cache entry which is the child of this folder * * Sets the size, etag and size to for cross-storage childs * - * @param array $data cache entry for the child + * @param array|ICacheEntry $data cache entry for the child * @param string $entryPath full path of the child entry */ public function addSubEntry($data, $entryPath) { |