homecache.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Files\Cache;
  9. class HomeCache extends Cache {
  10. /**
  11. * get the size of a folder and set it in the cache
  12. *
  13. * @param string $path
  14. * @return int
  15. */
  16. public function calculateFolderSize($path) {
  17. if ($path !== '/' and $path !== '') {
  18. return parent::calculateFolderSize($path);
  19. }
  20. $totalSize = 0;
  21. $entry = $this->get($path);
  22. if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
  23. $id = $entry['fileid'];
  24. $sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' .
  25. 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
  26. $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
  27. if ($row = $result->fetchRow()) {
  28. list($sum) = array_values($row);
  29. $totalSize = (int)$sum;
  30. if ($entry['size'] !== $totalSize) {
  31. $this->update($id, array('size' => $totalSize));
  32. }
  33. }
  34. }
  35. return $totalSize;
  36. }
  37. public function get($path) {
  38. $data = parent::get($path);
  39. if ($path === '' or $path === '/') {
  40. // only the size of the "files" dir counts
  41. $filesData = parent::get('files');
  42. if (isset($filesData['size'])) {
  43. $data['size'] = $filesData['size'];
  44. }
  45. }
  46. return $data;
  47. }
  48. }