From ca12130bd3ead5d5a04021d4cf2b0c3701761dd8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 8 Jun 2023 17:14:18 +0200 Subject: [PATCH] select the fileid first when looking for incomplete files this seems to improve mariadbs index selection Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 75775e2de2871..de09b9c42cb04 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -981,8 +981,12 @@ 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))) @@ -990,10 +994,19 @@ public function getIncomplete() { ->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; + } } /**