aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2025-02-12 15:29:26 +0100
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2025-02-14 11:00:07 +0100
commitce4d2713865789087056287b4428af80853434bc (patch)
tree1c5447f0851dd8be8b53e95b26a62ec92c666449
parent24f5acf0fe7b763385c45531d3288629d9e84bd6 (diff)
downloadnextcloud-server-ce4d2713865789087056287b4428af80853434bc.tar.gz
nextcloud-server-ce4d2713865789087056287b4428af80853434bc.zip
perf(files): faster query to fetch incomplete directoriesbackport/50781/stable29
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
-rw-r--r--lib/private/Files/Cache/Cache.php26
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreScanner.php2
2 files changed, 10 insertions, 18 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 8f783d2920f..d32f8bd1ae7 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -1,4 +1,5 @@
<?php
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -87,7 +88,7 @@ class Cache implements ICache {
protected array $partial = [];
protected string $storageId;
protected Storage $storageCache;
- protected IMimeTypeLoader$mimetypeLoader;
+ protected IMimeTypeLoader $mimetypeLoader;
protected IDBConnection $connection;
protected SystemConfig $systemConfig;
protected LoggerInterface $logger;
@@ -876,7 +877,7 @@ class Cache implements ICache {
* search for files by mimetype
*
* @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
- * where it will search for all mimetypes in the group ('image/*')
+ * where it will search for all mimetypes in the group ('image/*')
* @return ICacheEntry[] an array of cache entries where the mimetype matches the search
*/
public function searchByMime($mimetype) {
@@ -1068,28 +1069,19 @@ 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('fileid')
+ $query->select('path')
->from('filecache')
->whereStorageId($this->getNumericStorageId())
- ->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
+ ->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->orderBy('fileid', 'DESC')
->setMaxResults(1);
$result = $query->execute();
- $id = $result->fetchOne();
+ $path = $result->fetchOne();
$result->closeCursor();
- if ($id === false) {
- return false;
- }
-
- $path = $this->getPathById($id);
- return $path ?? false;
+ return $path === false ? false : (string)$path;
}
/**
@@ -1169,7 +1161,7 @@ class Cache implements ICache {
*/
public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
if ($sourceEntry->getId() < 0) {
- throw new \RuntimeException("Invalid source cache entry on copyFromCache");
+ throw new \RuntimeException('Invalid source cache entry on copyFromCache');
}
$data = $this->cacheEntryToArray($sourceEntry);
@@ -1180,7 +1172,7 @@ class Cache implements ICache {
$fileId = $this->put($targetPath, $data);
if ($fileId <= 0) {
- throw new \RuntimeException("Failed to copy to " . $targetPath . " from cache with source data " . json_encode($data) . " ");
+ throw new \RuntimeException('Failed to copy to ' . $targetPath . ' from cache with source data ' . json_encode($data) . ' ');
}
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
diff --git a/lib/private/Files/ObjectStore/ObjectStoreScanner.php b/lib/private/Files/ObjectStore/ObjectStoreScanner.php
index 8a9b844c47f..20e4e897fd0 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreScanner.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreScanner.php
@@ -80,7 +80,7 @@ class ObjectStoreScanner extends Scanner {
$query->select('path')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($this->cache->getNumericStorageId(), IQueryBuilder::PARAM_INT)))
- ->andWhere($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
+ ->andWhere($query->expr()->eq('size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->orderBy('path', 'DESC')
->setMaxResults(1);