diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-01-16 21:58:17 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-01-16 21:58:17 +0100 |
commit | 6871a150bd1309af0ca22e45487043d9640bb356 (patch) | |
tree | 242b6f5f43c5942996ec7c08b8167bf337803e02 | |
parent | bb43cf378b5e7c6a18a30d8fbb226b72f1e4eb88 (diff) | |
download | nextcloud-server-6871a150bd1309af0ca22e45487043d9640bb356.tar.gz nextcloud-server-6871a150bd1309af0ca22e45487043d9640bb356.zip |
Cache: use a database transition for scanning each folder
gives a massive speed improvement while scanning files
-rw-r--r-- | lib/files/cache/scanner.php | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index b62a093cec7..bf0ef01d6b3 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -83,14 +83,19 @@ class Scanner { * * @param string $path * @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive + * @param bool $onlyChilds * @return int the size of the scanned folder or -1 if the size is unknown at this stage */ - public function scan($path, $recursive = self::SCAN_RECURSIVE) { + public function scan($path, $recursive = self::SCAN_RECURSIVE, $onlyChilds = false) { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId)); - $this->scanFile($path); + $childQueue = array(); + if (!$onlyChilds) { + $this->scanFile($path); + } $size = 0; if ($dh = $this->storage->opendir($path)) { + \OC_DB::beginTransaction(); while ($file = readdir($dh)) { if ($file !== '.' and $file !== '..') { $child = ($path) ? $path . '/' . $file : $file; @@ -98,10 +103,12 @@ class Scanner { if ($data) { if ($data['mimetype'] === 'httpd/unix-directory') { if ($recursive === self::SCAN_RECURSIVE) { - $data['size'] = $this->scan($child, self::SCAN_RECURSIVE); + $childQueue[] = $child; + $data['size'] = 0; } else { $data['size'] = -1; } + } else { } if ($data['size'] === -1) { $size = -1; @@ -111,6 +118,15 @@ class Scanner { } } } + \OC_DB::commit(); + foreach ($childQueue as $child) { + $childSize = $this->scan($child, self::SCAN_RECURSIVE, true); + if ($childSize === -1) { + $size = -1; + } else { + $size += $childSize; + } + } if ($size !== -1) { $this->cache->put($path, array('size' => $size)); } |