mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
ignore metadata if table is empty
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
f313b12d54
commit
3af12b2a50
6 changed files with 34 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue