Skip to content

Commit

Permalink
ignore metadata if table is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 13, 2023
1 parent 96eb00a commit d463171
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function get($file) {
} elseif (!$data) {
return $data;
} else {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public function getFolderContentsById($fileId) {
$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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public function whereParentInParameter(string $parameter) {
return $this;
}

public function selectMetadata(): IMetadataQuery {
public function selectMetadata(): ?IMetadataQuery {
$metadataQuery = $this->filesMetadataManager->getMetadataQuery($this, $this->alias, 'fileid');
$metadataQuery->retrieveMetadata();
$metadataQuery?->retrieveMetadata();
return $metadataQuery;
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
$files = $result->fetchAll();

$rawEntries = array_map(function (array $data) use ($metadataQuery) {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];

Check failure on line 192 in lib/private/Files/Cache/QuerySearchHelper.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

lib/private/Files/Cache/QuerySearchHelper.php:192:24: RedundantCondition: Type array<array-key, mixed> for $<tmp coalesce var>7219 is never null (see https://psalm.dev/122)

Check failure on line 192 in lib/private/Files/Cache/QuerySearchHelper.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainNull

lib/private/Files/Cache/QuerySearchHelper.php:192:78: TypeDoesNotContainNull: Cannot resolve types for $<tmp coalesce var>7219 - array<array-key, mixed> does not contain null (see https://psalm.dev/090)

Check failure

Code scanning / Psalm

RedundantCondition Error

Type array<array-key, mixed> for $7219 is never null

Check failure

Code scanning / Psalm

TypeDoesNotContainNull Error

Cannot resolve types for $7219 - array<array-key, mixed> does not contain null
return Cache::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);

Expand Down
8 changes: 6 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,19 @@ public function deleteMetadata(int $fileId): void {
* @param string $fileIdField alias of the field that contains file ids
*
* @inheritDoc
* @return IMetadataQuery
* @return IMetadataQuery|null
* @see IMetadataQuery
* @since 28.0.0
*/
public function getMetadataQuery(
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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/public/FilesMetadata/IFilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public function deleteMetadata(int $fileId): void;
* @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
*/
public function getMetadataQuery(
IQueryBuilder $qb,
string $fileTableAlias,
string $fileIdField
): IMetadataQuery;
): ?IMetadataQuery;

/**
* returns all type of metadata currently available.
Expand Down

0 comments on commit d463171

Please sign in to comment.