]> source.dussan.org Git - nextcloud-server.git/commitdiff
select the fileid first when looking for incomplete files 39872/head
authorRobin Appelman <robin@icewind.nl>
Thu, 8 Jun 2023 15:14:18 +0000 (17:14 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 14 Aug 2023 19:15:41 +0000 (19:15 +0000)
this seems to improve mariadbs index selection

Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Cache/Cache.php

index bf459b2ff8691f5ad1e516ad130d9a67351f77af..9805fd1601fc45e08e51486133a4f7c5399b729b 100644 (file)
@@ -984,8 +984,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)))
@@ -993,15 +997,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;
        }
 
        /**