diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2023-11-14 09:28:47 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2023-11-14 09:28:58 -0100 |
commit | 3af12b2a50222c0e83273c939e5abdd747b82d9e (patch) | |
tree | c6651606efeb331a18c27ae28d94daf2a1340291 | |
parent | f313b12d54a831f3788bb44d7f51bb8f1ac54583 (diff) | |
download | nextcloud-server-3af12b2a50222c0e83273c939e5abdd747b82d9e.tar.gz nextcloud-server-3af12b2a50222c0e83273c939e5abdd747b82d9e.zip |
ignore metadata if table is empty
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Cache/CacheQueryBuilder.php | 9 | ||||
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 13 | ||||
-rw-r--r-- | lib/private/Files/Cache/SearchBuilder.php | 6 | ||||
-rw-r--r-- | lib/private/FilesMetadata/FilesMetadataManager.php | 8 | ||||
-rw-r--r-- | lib/public/FilesMetadata/IFilesMetadataManager.php | 4 |
6 files changed, 34 insertions, 10 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 240f02b3fba..27db4dfe809 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -178,7 +178,7 @@ class Cache implements ICache { } elseif (!$data) { return $data; } else { - $data['metadata'] = $metadataQuery->extractMetadata($data)->asArray(); + $data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? []; return self::cacheEntryFromData($data, $this->mimetypeLoader); } } @@ -250,7 +250,7 @@ class Cache implements ICache { $result->closeCursor(); return array_map(function (array $data) use ($metadataQuery) { - $data['metadata'] = $metadataQuery->extractMetadata($data)->asArray(); + $data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? []; return self::cacheEntryFromData($data, $this->mimetypeLoader); }, $files); } diff --git a/lib/private/Files/Cache/CacheQueryBuilder.php b/lib/private/Files/Cache/CacheQueryBuilder.php index a0fa7b6be43..365d28fc8c5 100644 --- a/lib/private/Files/Cache/CacheQueryBuilder.php +++ b/lib/private/Files/Cache/CacheQueryBuilder.php @@ -135,9 +135,14 @@ class CacheQueryBuilder extends QueryBuilder { return $this; } - public function selectMetadata(): IMetadataQuery { + /** + * join metadata to current query builder and returns an helper + * + * @return IMetadataQuery|null NULL if no metadata have never been generated + */ + public function selectMetadata(): ?IMetadataQuery { $metadataQuery = $this->filesMetadataManager->getMetadataQuery($this, $this->alias, 'fileid'); - $metadataQuery->retrieveMetadata(); + $metadataQuery?->retrieveMetadata(); return $metadataQuery; } } diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index aca998cc4a7..d8c5e66e129 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -67,6 +67,12 @@ class QuerySearchHelper { ); } + /** + * @param CacheQueryBuilder $query + * @param ISearchQuery $searchQuery + * @param array $caches + * @param IMetadataQuery|null $metadataQuery + */ protected function applySearchConstraints( CacheQueryBuilder $query, ISearchQuery $searchQuery, @@ -189,7 +195,12 @@ class QuerySearchHelper { $files = $result->fetchAll(); $rawEntries = array_map(function (array $data) use ($metadataQuery) { - $data['metadata'] = $metadataQuery->extractMetadata($data)->asArray(); + // migrate to null safe ... + if ($metadataQuery === null) { + $data['metadata'] = []; + } else { + $data['metadata'] = $metadataQuery->extractMetadata($data)->asArray(); + } return Cache::cacheEntryFromData($data, $this->mimetypeLoader); }, $files); diff --git a/lib/private/Files/Cache/SearchBuilder.php b/lib/private/Files/Cache/SearchBuilder.php index c3699cca63d..7d4a84bffbe 100644 --- a/lib/private/Files/Cache/SearchBuilder.php +++ b/lib/private/Files/Cache/SearchBuilder.php @@ -243,7 +243,11 @@ class SearchBuilder { } - private function getExtraOperatorField(ISearchComparison $operator, IMetadataQuery $metadataQuery): array { + private function getExtraOperatorField(ISearchComparison $operator, ?IMetadataQuery $metadataQuery): array { + if (null === $metadataQuery) { + throw new \InvalidArgumentException('IMetadataQuery is null while calling getExtraOperatorField'); + } + $field = $operator->getField(); $value = $operator->getValue(); $type = $operator->getType(); diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index 362db3678ae..e9d6e677baf 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -213,7 +213,7 @@ class FilesMetadataManager implements IFilesMetadataManager { * @param string $fileIdField alias of the field that contains file ids * * @inheritDoc - * @return IMetadataQuery + * @return IMetadataQuery|null * @see IMetadataQuery * @since 28.0.0 */ @@ -221,7 +221,11 @@ class FilesMetadataManager implements IFilesMetadataManager { IQueryBuilder $qb, string $fileTableAlias, string $fileIdField - ): IMetadataQuery { + ): ?IMetadataQuery { + // we don't want to join metadata table if never filled + if ($this->config->getAppValue('core', self::CONFIG_KEY, '') === '') { + return null; + } return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField); } diff --git a/lib/public/FilesMetadata/IFilesMetadataManager.php b/lib/public/FilesMetadata/IFilesMetadataManager.php index ebebf3e806b..78ea020e967 100644 --- a/lib/public/FilesMetadata/IFilesMetadataManager.php +++ b/lib/public/FilesMetadata/IFilesMetadataManager.php @@ -105,7 +105,7 @@ interface IFilesMetadataManager { * @param string $fileTableAlias alias of the table that contains data about files * @param string $fileIdField alias of the field that contains file ids * - * @return IMetadataQuery + * @return IMetadataQuery|null NULL if table are not set yet or never used * @see IMetadataQuery * @since 28.0.0 */ @@ -113,7 +113,7 @@ interface IFilesMetadataManager { IQueryBuilder $qb, string $fileTableAlias, string $fileIdField - ): IMetadataQuery; + ): ?IMetadataQuery; /** * returns all type of metadata currently available. |