Skip to content

Commit 6be32f7

Browse files
committed
Unencrypted size patch - for database optimization
1 parent 4c7e817 commit 6be32f7

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

lib/private/Files/Cache/Updater.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function propagate($path, $time = null) {
119119
* @param string $path
120120
* @param int $time
121121
*/
122-
public function update($path, $time = null) {
122+
public function update($path, $time = null, ?int $sizeDifference = null) {
123123
if (!$this->enabled or Scanner::isPartialFile($path)) {
124124
return;
125125
}
@@ -128,20 +128,22 @@ public function update($path, $time = null) {
128128
}
129129

130130
$data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false);
131-
if (
132-
isset($data['oldSize']) && isset($data['size']) &&
133-
!$data['encrypted'] // encryption is a pita and touches the cache itself
134-
) {
131+
132+
if (isset($data['oldSize']) && isset($data['size'])) {
135133
$sizeDifference = $data['size'] - $data['oldSize'];
136-
} else {
137-
// scanner didn't provide size info, fallback to full size calculation
138-
$sizeDifference = 0;
139-
if ($this->cache instanceof Cache) {
140-
$this->cache->correctFolderSize($path, $data);
141-
}
134+
}
135+
136+
// encryption is a pita and touches the cache itself
137+
if (isset($data['encrypted']) && !!$data['encrypted']) {
138+
$sizeDifference = null;
139+
}
140+
141+
// scanner didn't provide size info, fallback to full size calculation
142+
if ($this->cache instanceof Cache && $sizeDifference === null) {
143+
$this->cache->correctFolderSize($path, $data);
142144
}
143145
$this->correctParentStorageMtime($path);
144-
$this->propagator->propagateChange($path, $time, $sizeDifference);
146+
$this->propagator->propagateChange($path, $time, $sizeDifference ?? 0);
145147
}
146148

147149
/**

lib/private/Files/View.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ public function enableCacheUpdate(): void {
287287
$this->updaterEnabled = true;
288288
}
289289

290-
protected function writeUpdate(Storage $storage, string $internalPath, ?int $time = null): void {
290+
protected function writeUpdate(Storage $storage, string $internalPath, ?int $time = null, ?int $sizeDifference = null): void {
291291
if ($this->updaterEnabled) {
292292
if (is_null($time)) {
293293
$time = time();
294294
}
295-
$storage->getUpdater()->update($internalPath, $time);
295+
$storage->getUpdater()->update($internalPath, $time, $sizeDifference);
296296
}
297297
}
298298

@@ -1173,7 +1173,9 @@ private function basicOperation(string $operation, string $path, array $hooks =
11731173
$this->removeUpdate($storage, $internalPath);
11741174
}
11751175
if ($result !== false && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
1176-
$this->writeUpdate($storage, $internalPath);
1176+
$isCreateOperation = $operation === 'mkdir' || ($operation === 'file_put_contents' && in_array('create', $hooks, true));
1177+
$sizeDifference = $operation === 'mkdir' ? 0 : $result;
1178+
$this->writeUpdate($storage, $internalPath, null, $isCreateOperation ? $sizeDifference : null);
11771179
}
11781180
if ($result !== false && in_array('touch', $hooks)) {
11791181
$this->writeUpdate($storage, $internalPath, $extraParam);

lib/public/Files/Cache/IUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function propagate($path, $time = null);
5353
* @param int $time
5454
* @since 9.0.0
5555
*/
56-
public function update($path, $time = null);
56+
public function update($path, $time = null, ?int $sizeDifference = null);
5757

5858
/**
5959
* Remove $path from the cache and update the size, etag and mtime of the parent folders

0 commit comments

Comments
 (0)