diff options
author | Robin Appelman <robin@icewind.nl> | 2024-10-03 18:05:43 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-11-07 16:27:16 +0100 |
commit | b21c0265df47dea54655bc33645cb1b5e45a5928 (patch) | |
tree | 4bedf74369415e96c72c70a65fa4a55d3588e9a6 /lib | |
parent | 19ec79b3134bb2b78d900c05d62a913500eec282 (diff) | |
download | nextcloud-server-b21c0265df47dea54655bc33645cb1b5e45a5928.tar.gz nextcloud-server-b21c0265df47dea54655bc33645cb1b5e45a5928.zip |
test: add some minimal testing for metadata storagemetadata-storage-id
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/FilesMetadata/FilesMetadataManager.php | 4 | ||||
-rw-r--r-- | lib/private/FilesMetadata/Model/FilesMetadata.php | 10 | ||||
-rw-r--r-- | lib/private/FilesMetadata/Service/MetadataRequestService.php | 7 |
3 files changed, 16 insertions, 5 deletions
diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index b0a08c4f119..4846799b3d4 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -81,10 +81,10 @@ class FilesMetadataManager implements IFilesMetadataManager { try { /** @var FilesMetadata $metadata */ $metadata = $this->metadataRequestService->getMetadataFromFileId($node->getId()); - $metadata->setStorageId($storageId); } catch (FilesMetadataNotFoundException) { - $metadata = new FilesMetadata($node->getId(), $storageId); + $metadata = new FilesMetadata($node->getId()); } + $metadata->setStorageId($storageId); // if $process is LIVE, we enforce LIVE // if $process is NAMED, we go NAMED diff --git a/lib/private/FilesMetadata/Model/FilesMetadata.php b/lib/private/FilesMetadata/Model/FilesMetadata.php index d35e4a375e3..b66e1fe3711 100644 --- a/lib/private/FilesMetadata/Model/FilesMetadata.php +++ b/lib/private/FilesMetadata/Model/FilesMetadata.php @@ -27,10 +27,10 @@ class FilesMetadata implements IFilesMetadata { private bool $updated = false; private int $lastUpdate = 0; private string $syncToken = ''; + private ?int $storageId = null; public function __construct( private int $fileId = 0, - private ?int $storageId = null, ) { } @@ -47,6 +47,14 @@ class FilesMetadata implements IFilesMetadata { return $this->storageId; } + /** + * Set which storage the file this metadata belongs to. + * + * This helps with sharded filecache setups to know where to store the metadata + * + * @param int $storageId + * @return void + */ public function setStorageId(int $storageId): void { $this->storageId = $storageId; } diff --git a/lib/private/FilesMetadata/Service/MetadataRequestService.php b/lib/private/FilesMetadata/Service/MetadataRequestService.php index 4d36655cffa..c308ae1c9c8 100644 --- a/lib/private/FilesMetadata/Service/MetadataRequestService.php +++ b/lib/private/FilesMetadata/Service/MetadataRequestService.php @@ -29,8 +29,11 @@ class MetadataRequestService { } private function getStorageId(IFilesMetadata $filesMetadata): int { - if ($filesMetadata instanceof FilesMetadata && $filesMetadata->getStorageId()) { - return $filesMetadata->getStorageId(); + if ($filesMetadata instanceof FilesMetadata) { + $storage = $filesMetadata->getStorageId(); + if ($storage) { + return $storage; + } } // all code paths that lead to saving metadata *should* have the storage id set // this fallback is there just in case |