summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-11-09 16:14:54 +0100
committerRobin Appelman <robin@icewind.nl>2016-11-10 13:59:22 +0100
commitcbcdf69dc218a9767b2682c0a1825f9f36e78266 (patch)
tree8693c71dbd7917795b2e8bbf735f6fc7f9c07f09 /lib/private/Files
parent742c215946555371b2ae1e855cefa65e5cc712a3 (diff)
downloadnextcloud-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')
-rw-r--r--lib/private/Files/FileInfo.php40
-rw-r--r--lib/private/Files/View.php15
2 files changed, 43 insertions, 12 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) {
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index f36e2c2c64f..3514c829691 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -56,6 +56,7 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileNameTooLongException;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
+use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
use OCP\Files\UnseekableException;
@@ -1353,18 +1354,10 @@ class View {
//add the sizes of other mount points to the folder
$extOnly = ($includeMountPoints === 'ext');
$mounts = Filesystem::getMountManager()->findIn($path);
- foreach ($mounts as $mount) {
+ $info->setSubMounts(array_filter($mounts, function(IMountPoint $mount) use ($extOnly) {
$subStorage = $mount->getStorage();
- if ($subStorage) {
- // exclude shared storage ?
- if ($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage) {
- continue;
- }
- $subCache = $subStorage->getCache('');
- $rootEntry = $subCache->get('');
- $info->addSubEntry($rootEntry, $mount->getMountPoint());
- }
- }
+ return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
+ }));
}
}