Cache: use a database transition for scanning each folder

gives a massive speed improvement while scanning files
This commit is contained in:
Robin Appelman 2013-01-16 21:58:17 +01:00
parent bb43cf378b
commit 6871a150bd
1 changed files with 19 additions and 3 deletions

View File

@ -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));
}