summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2023-08-16 15:43:43 +0200
committerGitHub <noreply@github.com>2023-08-16 15:43:43 +0200
commitf95ed098c56359151432e5640c8b43ce4958cd93 (patch)
tree9a1ddd376a596543b967d55ba20b8e91f02ae0f2
parentde7822477c24e74f24052ea8db36ad4c8b0aaa54 (diff)
parenta5cd892caa42f66cfaea0089b6b7bc0e04327a3a (diff)
downloadnextcloud-server-f95ed098c56359151432e5640c8b43ce4958cd93.tar.gz
nextcloud-server-f95ed098c56359151432e5640c8b43ce4958cd93.zip
Merge pull request #39871 from nextcloud/backport/38714/stable27
[stable27] select the fileid first when looking for incomplete files
-rw-r--r--lib/private/Files/Cache/Cache.php14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 1adc14c626c..76b2fa942cc 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -1025,8 +1025,12 @@ class Cache implements ICache {
* @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)))
@@ -1034,15 +1038,15 @@ class Cache implements ICache {
->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;
}
/**