2013-11-08 15:57:28 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Files\Cache;
|
|
|
|
|
|
|
|
class HomeCache extends Cache {
|
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function calculateFolderSize($path) {
|
2014-01-07 20:41:04 +04:00
|
|
|
if ($path !== '/' and $path !== '' and $path !== 'files') {
|
2013-11-12 17:17:55 +04:00
|
|
|
return parent::calculateFolderSize($path);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:57:28 +04:00
|
|
|
$totalSize = 0;
|
|
|
|
$entry = $this->get($path);
|
|
|
|
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$id = $entry['fileid'];
|
2013-11-12 17:17:55 +04:00
|
|
|
$sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' .
|
|
|
|
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
|
2013-11-08 15:57:28 +04:00
|
|
|
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
|
|
|
if ($row = $result->fetchRow()) {
|
2013-11-12 17:17:55 +04:00
|
|
|
list($sum) = array_values($row);
|
|
|
|
$totalSize = (int)$sum;
|
2013-11-08 15:57:28 +04:00
|
|
|
if ($entry['size'] !== $totalSize) {
|
|
|
|
$this->update($id, array('size' => $totalSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $totalSize;
|
|
|
|
}
|
2013-11-18 20:39:52 +04:00
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
*/
|
2013-11-18 20:39:52 +04:00
|
|
|
public function get($path) {
|
|
|
|
$data = parent::get($path);
|
|
|
|
if ($path === '' or $path === '/') {
|
|
|
|
// only the size of the "files" dir counts
|
|
|
|
$filesData = parent::get('files');
|
|
|
|
|
|
|
|
if (isset($filesData['size'])) {
|
|
|
|
$data['size'] = $filesData['size'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2013-11-08 15:57:28 +04:00
|
|
|
}
|