diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-03-07 12:48:57 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-03-07 12:49:06 -0100 |
commit | 3fa5e598a8e74cc3c89b3c43a370bfcbef5115c5 (patch) | |
tree | 551f0be5eaf136d877b1de5ef0eabe885c3faf42 /lib | |
parent | e17424fa11e25828cce3756e9c076f08f9c45e01 (diff) | |
download | nextcloud-server-3fa5e598a8e74cc3c89b3c43a370bfcbef5115c5.tar.gz nextcloud-server-3fa5e598a8e74cc3c89b3c43a370bfcbef5115c5.zip |
feat(metadata): get deprecated status using file etag
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
6 files changed, 89 insertions, 13 deletions
diff --git a/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php b/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php index 7bfe36e9d41..b57dfa317e4 100644 --- a/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php +++ b/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php @@ -72,6 +72,12 @@ class GenerateBlurhashMetadata implements IEventListener { return; } + $currentEtag = $file->getEtag(); + $metadata = $event->getMetadata(); + if ($metadata->getEtag('blurhash') === $currentEtag) { + return; + } + // too heavy to run on the live thread, request a rerun as a background job if ($event instanceof MetadataLiveEvent) { $event->requestBackgroundJob(); @@ -95,8 +101,8 @@ class GenerateBlurhashMetadata implements IEventListener { return; } - $metadata = $event->getMetadata(); - $metadata->setString('blurhash', $this->generateBlurHash($image)); + $metadata->setString('blurhash', $this->generateBlurHash($image)) + ->setEtag('blurhash', $currentEtag); } /** diff --git a/lib/private/FilesMetadata/Model/FilesMetadata.php b/lib/private/FilesMetadata/Model/FilesMetadata.php index 84cb177bc37..3de72357431 100644 --- a/lib/private/FilesMetadata/Model/FilesMetadata.php +++ b/lib/private/FilesMetadata/Model/FilesMetadata.php @@ -156,6 +156,23 @@ class FilesMetadata implements IFilesMetadata { $this->metadata[$key]->setEditPermission($permission); } + + public function getEtag(string $key): string { + if (!array_key_exists($key, $this->metadata)) { + throw new FilesMetadataNotFoundException(); + } + + return $this->metadata[$key]->getEtag(); + } + + public function setEtag(string $key, string $etag): void { + if (!array_key_exists($key, $this->metadata)) { + throw new FilesMetadataNotFoundException(); + } + + $this->metadata[$key]->setEtag($etag); + } + /** * @param string $key metadata key * diff --git a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php index 90f1554180d..70dec89650a 100644 --- a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php +++ b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php @@ -38,6 +38,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper { private string $type; /** @var string|int|float|bool|array|string[]|int[] */ private mixed $value = null; + private string $etag = ''; private bool $indexed = false; private int $editPermission = self::EDIT_FORBIDDEN; @@ -351,6 +352,27 @@ class MetadataValueWrapper implements IMetadataValueWrapper { } /** + * @inheritDoc + * @return string stored etag + * @since 29.0.0 + */ + public function getEtag(): string { + return $this->etag; + } + + /** + * @param string $etag etag value + * + * @inheritDoc + * @return self + * @since 29.0.0 + */ + public function setEtag(string $etag): self { + $this->etag = $etag; + return $this; + } + + /** * @param bool $indexed TRUE to set the stored value as an indexed value * * @inheritDoc @@ -405,6 +427,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper { public function import(array $data): self { $this->value = $data['value'] ?? null; $this->type = $data['type'] ?? ''; + $this->setEtag($data['etag'] ?? ''); $this->setIndexed($data['indexed'] ?? false); $this->setEditPermission($data['editPermission'] ?? self::EDIT_FORBIDDEN); return $this; @@ -414,6 +437,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper { return [ 'value' => ($emptyValues) ? null : $this->value, 'type' => $this->getType(), + 'etag' => $this->getEtag(), 'indexed' => $this->isIndexed(), 'editPermission' => $this->getEditPermission() ]; diff --git a/lib/private/FilesMetadata/Service/MetadataRequestService.php b/lib/private/FilesMetadata/Service/MetadataRequestService.php index cdce624d75c..b6d1b277a00 100644 --- a/lib/private/FilesMetadata/Service/MetadataRequestService.php +++ b/lib/private/FilesMetadata/Service/MetadataRequestService.php @@ -74,16 +74,12 @@ class MetadataRequestService { try { $qb = $this->dbConnection->getQueryBuilder(); $qb->select('json', 'sync_token')->from(self::TABLE_METADATA); - $qb->where( - $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) - ); + $qb->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $result = $qb->executeQuery(); $data = $result->fetch(); $result->closeCursor(); } catch (Exception $e) { - $this->logger->warning( - 'exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId] - ); + $this->logger->warning('exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId]); throw new FilesMetadataNotFoundException(); } @@ -100,8 +96,6 @@ class MetadataRequestService { /** * returns metadata for multiple file ids * - * If - * * @param array $fileIds file ids * * @return array File ID is the array key, files without metadata are not returned in the array @@ -110,9 +104,7 @@ class MetadataRequestService { public function getMetadataFromFileIds(array $fileIds): array { $qb = $this->dbConnection->getQueryBuilder(); $qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA); - $qb->where( - $qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)) - ); + $qb->where($qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); $list = []; $result = $qb->executeQuery(); diff --git a/lib/public/FilesMetadata/Model/IFilesMetadata.php b/lib/public/FilesMetadata/Model/IFilesMetadata.php index 7697a2f37ad..024b21039bc 100644 --- a/lib/public/FilesMetadata/Model/IFilesMetadata.php +++ b/lib/public/FilesMetadata/Model/IFilesMetadata.php @@ -37,12 +37,14 @@ use OCP\FilesMetadata\Exceptions\FilesMetadataTypeException; * "mymeta": { * "value": "this is a test", * "type": "string", + * "etag": "abcd1234", * "indexed": false, * "editPermission": 1 * }, * "myapp-anothermeta": { * "value": 42, * "type": "int", + * "etag": "0987zyxw", * "indexed": true, * "editPermission": 0 * } @@ -113,6 +115,23 @@ interface IFilesMetadata extends JsonSerializable { public function isIndex(string $key): bool; /** + * returns file etag stored during the last update of the metadata key + * + * @param string $key metadata key + * @return string + * @since 29.0.0 + */ + public function getEtag(string $key): string; + + /** + * set file etag + * + * @param string $key metadata key + * @since 29.0.0 + */ + public function setEtag(string $key, string $etag): void; + + /** * set remote edit permission * (Webdav PROPPATCH) * diff --git a/lib/public/FilesMetadata/Model/IMetadataValueWrapper.php b/lib/public/FilesMetadata/Model/IMetadataValueWrapper.php index d34cd070c8b..6c551efea81 100644 --- a/lib/public/FilesMetadata/Model/IMetadataValueWrapper.php +++ b/lib/public/FilesMetadata/Model/IMetadataValueWrapper.php @@ -286,6 +286,24 @@ interface IMetadataValueWrapper extends JsonSerializable { public function getValueAny(): mixed; /** + * get stored etag value + * + * @return string stored etag + * @since 29.0.0 + */ + public function getEtag(): string; + + /** + * set etag value + * + * @param string $etag etag value + * + * @return self + * @since 29.0.0 + */ + public function setEtag(string $etag): self; + + /** * @param bool $indexed TRUE to set the stored value as an indexed value * * @return self |