Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] perf(files): faster query to fetch incomplete directories #50796

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Cache implements ICache {
protected array $partial = [];
protected string $storageId;
protected Storage $storageCache;
protected IMimeTypeLoader$mimetypeLoader;
protected IMimeTypeLoader $mimetypeLoader;
protected IDBConnection $connection;
protected SystemConfig $systemConfig;
protected LoggerInterface $logger;
Expand Down Expand Up @@ -864,7 +864,7 @@ public function search($pattern) {
* search for files by mimetype
*
* @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
* where it will search for all mimetypes in the group ('image/*')
* where it will search for all mimetypes in the group ('image/*')
* @return ICacheEntry[] an array of cache entries where the mimetype matches the search
*/
public function searchByMime($mimetype) {
Expand Down Expand Up @@ -917,7 +917,7 @@ public function getIncompleteChildrenCount($fileId) {
->from('filecache')
->whereParent($fileId)
->whereStorageId($this->getNumericStorageId())
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));

$result = $query->execute();
$size = (int)$result->fetchOne();
Expand Down Expand Up @@ -1058,28 +1058,19 @@ public function getAll() {
* @return string|false the path of the folder or false when no folder matched
*/
public function getIncomplete() {
// we select the fileid here first instead of directly selecting the path since this helps mariadb/mysql
// to use the correct index.
// The overhead of this should be minimal since the cost of selecting the path by id should be much lower
// than the cost of finding an item with size < 0
$query = $this->getQueryBuilder();
$query->select('fileid')
$query->select('path')
->from('filecache')
->whereStorageId($this->getNumericStorageId())
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->orderBy('fileid', 'DESC')
->setMaxResults(1);

$result = $query->execute();
$id = $result->fetchOne();
$path = $result->fetchOne();
$result->closeCursor();

if ($id === false) {
return false;
}

$path = $this->getPathById($id);
return $path ?? false;
return $path === false ? false : (string)$path;
}

/**
Expand Down Expand Up @@ -1159,7 +1150,7 @@ public function normalize($path) {
*/
public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
if ($sourceEntry->getId() < 0) {
throw new \RuntimeException("Invalid source cache entry on copyFromCache");
throw new \RuntimeException('Invalid source cache entry on copyFromCache');
}
$data = $this->cacheEntryToArray($sourceEntry);

Expand All @@ -1170,7 +1161,7 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str

$fileId = $this->put($targetPath, $data);
if ($fileId <= 0) {
throw new \RuntimeException("Failed to copy to " . $targetPath . " from cache with source data " . json_encode($data) . " ");
throw new \RuntimeException('Failed to copy to ' . $targetPath . ' from cache with source data ' . json_encode($data) . ' ');
}
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/ObjectStore/ObjectStoreScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function getIncomplete() {
$query->select('path')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($this->cache->getNumericStorageId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->orderBy('path', 'DESC')
->setMaxResults(1);

Expand Down
Loading