Skip to content

Commit d463171

Browse files
committed
ignore metadata if table is empty
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 96eb00a commit d463171

5 files changed

Lines changed: 13 additions & 9 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function get($file) {
178178
} elseif (!$data) {
179179
return $data;
180180
} else {
181-
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
181+
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
182182
return self::cacheEntryFromData($data, $this->mimetypeLoader);
183183
}
184184
}
@@ -250,7 +250,7 @@ public function getFolderContentsById($fileId) {
250250
$result->closeCursor();
251251

252252
return array_map(function (array $data) use ($metadataQuery) {
253-
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
253+
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
254254
return self::cacheEntryFromData($data, $this->mimetypeLoader);
255255
}, $files);
256256
}

lib/private/Files/Cache/CacheQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public function whereParentInParameter(string $parameter) {
135135
return $this;
136136
}
137137

138-
public function selectMetadata(): IMetadataQuery {
138+
public function selectMetadata(): ?IMetadataQuery {
139139
$metadataQuery = $this->filesMetadataManager->getMetadataQuery($this, $this->alias, 'fileid');
140-
$metadataQuery->retrieveMetadata();
140+
$metadataQuery?->retrieveMetadata();
141141
return $metadataQuery;
142142
}
143143
}

lib/private/Files/Cache/QuerySearchHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
189189
$files = $result->fetchAll();
190190

191191
$rawEntries = array_map(function (array $data) use ($metadataQuery) {
192-
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
192+
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
193193
return Cache::cacheEntryFromData($data, $this->mimetypeLoader);
194194
}, $files);
195195

lib/private/FilesMetadata/FilesMetadataManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,19 @@ public function deleteMetadata(int $fileId): void {
214214
* @param string $fileIdField alias of the field that contains file ids
215215
*
216216
* @inheritDoc
217-
* @return IMetadataQuery
217+
* @return IMetadataQuery|null
218218
* @see IMetadataQuery
219219
* @since 28.0.0
220220
*/
221221
public function getMetadataQuery(
222222
IQueryBuilder $qb,
223223
string $fileTableAlias,
224224
string $fileIdField
225-
): IMetadataQuery {
225+
): ?IMetadataQuery {
226+
// we don't want to join metadata table if never filled
227+
if ($this->config->getAppValue('core', self::CONFIG_KEY, '') === '') {
228+
return null;
229+
}
226230
return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField);
227231
}
228232

lib/public/FilesMetadata/IFilesMetadataManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public function deleteMetadata(int $fileId): void;
106106
* @param string $fileTableAlias alias of the table that contains data about files
107107
* @param string $fileIdField alias of the field that contains file ids
108108
*
109-
* @return IMetadataQuery
109+
* @return IMetadataQuery|null NULL if table are not set yet or never used
110110
* @see IMetadataQuery
111111
* @since 28.0.0
112112
*/
113113
public function getMetadataQuery(
114114
IQueryBuilder $qb,
115115
string $fileTableAlias,
116116
string $fileIdField
117-
): IMetadataQuery;
117+
): ?IMetadataQuery;
118118

119119
/**
120120
* returns all type of metadata currently available.

0 commit comments

Comments
 (0)