Skip to content

Commit 2e58d36

Browse files
committed
feat: Implement custom Updater for object store storage
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 4cd026a commit 2e58d36

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@
16461646
'OC\\Files\\ObjectStore\\Mapper' => $baseDir . '/lib/private/Files/ObjectStore/Mapper.php',
16471647
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
16481648
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
1649+
'OC\\Files\\ObjectStore\\ObjectStoreUpdater' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreUpdater.php',
16491650
'OC\\Files\\ObjectStore\\PrimaryObjectStoreConfig' => $baseDir . '/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php',
16501651
'OC\\Files\\ObjectStore\\S3' => $baseDir . '/lib/private/Files/ObjectStore/S3.php',
16511652
'OC\\Files\\ObjectStore\\S3ConfigTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
16871687
'OC\\Files\\ObjectStore\\Mapper' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/Mapper.php',
16881688
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
16891689
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
1690+
'OC\\Files\\ObjectStore\\ObjectStoreUpdater' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreUpdater.php',
16901691
'OC\\Files\\ObjectStore\\PrimaryObjectStoreConfig' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php',
16911692
'OC\\Files\\ObjectStore\\S3' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3.php',
16921693
'OC\\Files\\ObjectStore\\S3ConfigTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',

lib/private/Files/Cache/Updater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private function updateStorageMTimeOnly($internalPath) {
272272
*
273273
* @param string $internalPath
274274
*/
275-
private function correctParentStorageMtime($internalPath) {
275+
public function correctParentStorageMtime($internalPath) {
276276
$parentId = $this->cache->getParentId($internalPath);
277277
$parent = dirname($internalPath);
278278
if ($parentId != -1) {

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\Files\Cache\ICache;
1919
use OCP\Files\Cache\ICacheEntry;
2020
use OCP\Files\Cache\IScanner;
21+
use OCP\Files\Cache\IUpdater;
2122
use OCP\Files\FileInfo;
2223
use OCP\Files\GenericFileException;
2324
use OCP\Files\NotFoundException;
@@ -474,6 +475,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
474475
}
475476
// update stat with new data
476477
$mTime = time();
478+
$oldSize = $stat['size'] ?? 0;
477479
$stat['size'] = (int)$size;
478480
$stat['mtime'] = $mTime;
479481
$stat['storage_mtime'] = $mTime;
@@ -571,6 +573,9 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
571573
}
572574
}
573575

576+
$this->getUpdater()->correctParentStorageMtime($path);
577+
$this->propagator->propagateChange($path, $mTime, $stat['size'] - $oldSize);
578+
574579
return $size;
575580
}
576581

@@ -824,4 +829,18 @@ public function cancelChunkedWrite(string $targetPath, string $writeToken): void
824829
public function setPreserveCacheOnDelete(bool $preserve) {
825830
$this->preserveCacheItemsOnDelete = $preserve;
826831
}
832+
833+
public function getUpdater(?IStorage $storage = null): IUpdater {
834+
if (!$storage) {
835+
$storage = $this;
836+
}
837+
if (!$storage->instanceOfStorage(self::class)) {
838+
throw new \InvalidArgumentException('Storage is not of the correct class');
839+
}
840+
/** @var self $storage */
841+
if (!isset($storage->updater)) {
842+
$storage->updater = new ObjectStoreUpdater($storage);
843+
}
844+
return $storage->updater;
845+
}
827846
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-only
6+
*/
7+
namespace OC\Files\ObjectStore;
8+
9+
use OC\Files\Cache\Updater;
10+
use OCP\Files\Storage\IStorage;
11+
12+
/**
13+
* Custom wrapper around the Updater for ObjectStoreStorage.
14+
* This wrapper will skip updating the cache in some scenario.
15+
* This is because a lot of cache management is already done in ObjectStoreStorage.
16+
*/
17+
class ObjectStoreUpdater extends Updater {
18+
public function getPropagator() {
19+
return parent::getPropagator();
20+
}
21+
22+
public function propagate($path, $time = null) {
23+
parent::propagate($path, $time);
24+
}
25+
26+
public function update($path, $time = null, ?int $sizeDifference = null) {
27+
// Noop
28+
}
29+
30+
public function remove($path) {
31+
parent::remove($path);
32+
}
33+
34+
public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
35+
parent::renameFromStorage($sourceStorage, $source, $target);
36+
}
37+
38+
public function copyFromStorage(IStorage $sourceStorage, string $source, string $target): void {
39+
parent::copyFromStorage($sourceStorage, $source, $target);
40+
}
41+
}

lib/public/Files/Cache/IUpdater.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getPropagator();
2828
*
2929
* @param string $path the path of the file to propagate the changes for
3030
* @param int|null $time the timestamp to set as mtime for the parent folders, if left out the current time is used
31+
* @return void
3132
* @since 9.0.0
3233
*/
3334
public function propagate($path, $time = null);
@@ -37,6 +38,7 @@ public function propagate($path, $time = null);
3738
*
3839
* @param string $path
3940
* @param int $time
41+
* @return void
4042
* @since 9.0.0
4143
*/
4244
public function update($path, $time = null, ?int $sizeDifference = null);
@@ -45,6 +47,7 @@ public function update($path, $time = null, ?int $sizeDifference = null);
4547
* Remove $path from the cache and update the size, etag and mtime of the parent folders
4648
*
4749
* @param string $path
50+
* @return void
4851
* @since 9.0.0
4952
*/
5053
public function remove($path);
@@ -55,6 +58,7 @@ public function remove($path);
5558
* @param IStorage $sourceStorage
5659
* @param string $source
5760
* @param string $target
61+
* @return void
5862
* @since 9.0.0
5963
*/
6064
public function renameFromStorage(IStorage $sourceStorage, $source, $target);

0 commit comments

Comments
 (0)