diff options
author | Robin Appelman <robin@icewind.nl> | 2022-04-13 16:05:45 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-08-16 13:54:26 +0200 |
commit | 1374cbee3e5d44ecec0a0784b3ab3a5afcc0d2ac (patch) | |
tree | c628e036930e72c11714c60b825cc38a4489e550 /lib/private/Files/Cache/Cache.php | |
parent | 5e375d9092efd1e40a0ed37dfd2c208598b27bb9 (diff) | |
download | nextcloud-server-1374cbee3e5d44ecec0a0784b3ab3a5afcc0d2ac.tar.gz nextcloud-server-1374cbee3e5d44ecec0a0784b3ab3a5afcc0d2ac.zip |
store unencrypted size in the unencrypted_size column
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Cache/Cache.php')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 9a7ffdab025..51008896373 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -37,6 +37,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OC\Files\Cache; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; @@ -188,6 +189,7 @@ class Cache implements ICache { $data['fileid'] = (int)$data['fileid']; $data['parent'] = (int)$data['parent']; $data['size'] = 0 + $data['size']; + $data['unencrypted_size'] = 0 + ($data['unencrypted_size'] ?? 0); $data['mtime'] = (int)$data['mtime']; $data['storage_mtime'] = (int)$data['storage_mtime']; $data['encryptedVersion'] = (int)$data['encrypted']; @@ -428,7 +430,7 @@ class Cache implements ICache { protected function normalizeData(array $data): array { $fields = [ 'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', - 'etag', 'permissions', 'checksum', 'storage']; + 'etag', 'permissions', 'checksum', 'storage', 'unencrypted_size']; $extensionFields = ['metadata_etag', 'creation_time', 'upload_time']; $doNotCopyStorageMTime = false; @@ -873,18 +875,32 @@ class Cache implements ICache { $id = $entry['fileid']; $query = $this->getQueryBuilder(); - $query->selectAlias($query->func()->sum('size'), 'f1') - ->selectAlias($query->func()->min('size'), 'f2') + $query->select('size', 'unencrypted_size') ->from('filecache') - ->whereStorageId($this->getNumericStorageId()) ->whereParent($id); $result = $query->execute(); - $row = $result->fetch(); + $rows = $result->fetchAll(); $result->closeCursor(); - if ($row) { - [$sum, $min] = array_values($row); + if ($rows) { + $sizes = array_map(function (array $row) { + return (int)$row['size']; + }, $rows); + $unencryptedOnlySizes = array_map(function (array $row) { + return (int)$row['unencrypted_size']; + }, $rows); + $unencryptedSizes = array_map(function (array $row) { + return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size']: $row['size']); + }, $rows); + + $sum = array_sum($sizes); + $min = min($sizes); + + $unencryptedSum = array_sum($unencryptedSizes); + $unencryptedMin = min($unencryptedSizes); + $unencryptedMax = max($unencryptedOnlySizes); + $sum = 0 + $sum; $min = 0 + $min; if ($min === -1) { @@ -892,8 +908,23 @@ class Cache implements ICache { } else { $totalSize = $sum; } + if ($unencryptedMin === -1 || $min === -1) { + $unencryptedTotal = $unencryptedMin; + } else { + $unencryptedTotal = $unencryptedSum; + } if ($entry['size'] !== $totalSize) { - $this->update($id, ['size' => $totalSize]); + // only set unencrypted size for a folder if any child entries have it set + if ($unencryptedMax > 0) { + $this->update($id, [ + 'size' => $totalSize, + 'unencrypted_size' => $unencryptedTotal, + ]); + } else { + $this->update($id, [ + 'size' => $totalSize, + ]); + } } } } |