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

select the fileid first when looking for incomplete files #38714

Merged
merged 1 commit into from
Aug 14, 2023
Merged
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
14 changes: 9 additions & 5 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,24 +1012,28 @@ 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();

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

// Make sure Oracle does not continue with null for empty strings
return (string)$path;
$path = $this->getPathById($id);
return $path ?? false;
}

/**
Expand Down