diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-07-29 10:22:44 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-07-29 10:22:44 -0400 |
commit | 1faac6108c0c51d28021eb0676db9ad2b94a6f3d (patch) | |
tree | 2ec204443f9576fb2462d449406d7f69a0690071 | |
parent | dd4e33fe6b1cf9feccaeae33c81fc8b08fb24d4d (diff) | |
download | nextcloud-server-1faac6108c0c51d28021eb0676db9ad2b94a6f3d.tar.gz nextcloud-server-1faac6108c0c51d28021eb0676db9ad2b94a6f3d.zip |
Use query to calculate folder size
-rw-r--r-- | lib/files/cache/cache.php | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 458df56141c..c3d11ab4cfe 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -489,19 +489,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; |