Skip to content

Commit ca12130

Browse files
committed
select the fileid first when looking for incomplete files
this seems to improve mariadbs index selection Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 5738ce5 commit ca12130

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,19 +981,32 @@ public function getAll() {
981981
* @return string|false the path of the folder or false when no folder matched
982982
*/
983983
public function getIncomplete() {
984+
// we select the fileid here first instead of directly selecting the path since this helps mariadb/mysql
985+
// to use the correct index.
986+
// The overhead of this should be minimal since the cost of selecting the path by id should be much lower
987+
// than the cost of finding an item with size < 0
984988
$query = $this->getQueryBuilder();
985-
$query->select('path')
989+
$query->select('fileid')
986990
->from('filecache')
987991
->whereStorageId($this->getNumericStorageId())
988992
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
989993
->orderBy('fileid', 'DESC')
990994
->setMaxResults(1);
991995

992996
$result = $query->execute();
993-
$path = $result->fetchOne();
997+
$id = $result->fetchOne();
994998
$result->closeCursor();
995999

996-
return $path;
1000+
if ($id === false) {
1001+
return false;
1002+
}
1003+
1004+
$path = $this->getPathById($id);
1005+
if ($path === null) {
1006+
return false;
1007+
} else {
1008+
return $path;
1009+
}
9971010
}
9981011

9991012
/**

0 commit comments

Comments
 (0)