Skip to content

Commit

Permalink
select the fileid first when looking for incomplete files
Browse files Browse the repository at this point in the history
this seems to improve mariadbs index selection

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jun 22, 2023
1 parent 5738ce5 commit ca12130
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,19 +981,32 @@ 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('path')
$query->select('fileid')
->from('filecache')
->whereStorageId($this->getNumericStorageId())
->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->orderBy('fileid', 'DESC')
->setMaxResults(1);

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

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

$path = $this->getPathById($id);
if ($path === null) {
return false;
} else {
return $path;
}
}

/**
Expand Down

0 comments on commit ca12130

Please sign in to comment.