Skip to content

Commit d056e4d

Browse files
Altahrimbackportbot[bot]
authored andcommitted
perf(files): faster query to fetch incomplete directories
Signed-off-by: Benjamin Gaussorgues <[email protected]>
1 parent 965526c commit d056e4d

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ public function getIncompleteChildrenCount($fileId) {
926926
->from('filecache')
927927
->whereParent($fileId)
928928
->whereStorageId($this->getNumericStorageId())
929-
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
929+
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
930930

931931
$result = $query->executeQuery();
932932
$size = (int)$result->fetchOne();
@@ -1067,28 +1067,19 @@ public function getAll() {
10671067
* @return string|false the path of the folder or false when no folder matched
10681068
*/
10691069
public function getIncomplete() {
1070-
// we select the fileid here first instead of directly selecting the path since this helps mariadb/mysql
1071-
// to use the correct index.
1072-
// The overhead of this should be minimal since the cost of selecting the path by id should be much lower
1073-
// than the cost of finding an item with size < 0
10741070
$query = $this->getQueryBuilder();
1075-
$query->select('fileid')
1071+
$query->select('path')
10761072
->from('filecache')
10771073
->whereStorageId($this->getNumericStorageId())
1078-
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
1074+
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
10791075
->orderBy('fileid', 'DESC')
10801076
->setMaxResults(1);
10811077

10821078
$result = $query->executeQuery();
1083-
$id = $result->fetchOne();
1079+
$path = $result->fetchOne();
10841080
$result->closeCursor();
10851081

1086-
if ($id === false) {
1087-
return false;
1088-
}
1089-
1090-
$path = $this->getPathById($id);
1091-
return $path ?? false;
1082+
return $path === false ? false : (string)$path;
10921083
}
10931084

10941085
/**

lib/private/Files/ObjectStore/ObjectStoreScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function getIncomplete() {
6161
$query->select('path')
6262
->from('filecache')
6363
->where($query->expr()->eq('storage', $query->createNamedParameter($this->cache->getNumericStorageId(), IQueryBuilder::PARAM_INT)))
64-
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
64+
->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
6565
->orderBy('path', 'DESC')
6666
->setMaxResults(1);
6767

0 commit comments

Comments
 (0)