aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-10-03 18:05:43 +0200
committerRobin Appelman <robin@icewind.nl>2024-11-07 16:27:16 +0100
commitb21c0265df47dea54655bc33645cb1b5e45a5928 (patch)
tree4bedf74369415e96c72c70a65fa4a55d3588e9a6 /lib
parent19ec79b3134bb2b78d900c05d62a913500eec282 (diff)
downloadnextcloud-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.php4
-rw-r--r--lib/private/FilesMetadata/Model/FilesMetadata.php10
-rw-r--r--lib/private/FilesMetadata/Service/MetadataRequestService.php7
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