]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use query to calculate folder size
authorMichael Gapczynski <mtgap@owncloud.com>
Mon, 29 Jul 2013 14:22:44 +0000 (10:22 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Fri, 2 Aug 2013 13:58:38 +0000 (09:58 -0400)
lib/files/cache/cache.php

index f605d72a6b398f4559a2bab2f2677a976d01f1bd..bc8b07db1a055ba38dbdc003d17d3355fe25877a 100644 (file)
@@ -503,19 +503,22 @@ class Cache {
                $entry = $this->get($path);
                if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
                        $id = $entry['fileid'];
-                       $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?';
+                       $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` '.
+                               'WHERE `parent` = ? AND `storage` = ?';
                        $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
-                       while ($row = $result->fetchRow()) {
-                               $size = (int)$row['size'];
-                               if ($size === -1) {
-                                       $totalSize = -1;
-                                       break;
+                       if ($row = $result->fetchRow()) {
+                               list($sum, $min) = array_values($row);
+                               $sum = (int)$sum;
+                               $min = (int)$min;
+                               if ($min === -1) {
+                                       $totalSize = $min;
                                } else {
-                                       $totalSize += $size;
+                                       $totalSize = $sum;
                                }
-                       }
-                       if ($entry['size'] !== $totalSize) {
-                               $this->update($id, array('size' => $totalSize));
+                               if ($entry['size'] !== $totalSize) {
+                                       $this->update($id, array('size' => $totalSize));
+                               }
+                               
                        }
                }
                return $totalSize;