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 175e8cf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 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
9 changes: 7 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ public function whereParentInParameter(string $parameter) {
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;
}
}
6 changes: 6 additions & 0 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ protected function getQueryBuilder() {
);
}

/**
* @param CacheQueryBuilder $query
* @param ISearchQuery $searchQuery
* @param array $caches
* @param IMetadataQuery|null $metadataQuery
*/
protected function applySearchConstraints(
CacheQueryBuilder $query,
ISearchQuery $searchQuery,
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 175e8cf

Please sign in to comment.