Skip to content

Commit 51075dc

Browse files
authored
Merge pull request #59901 from nextcloud/delay-storage-cache
perf: delay loading storage info in Cache untill needed
2 parents 0ea5449 + 17a7a95 commit 51075dc

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ class Cache implements ICache {
6161
*/
6262
protected array $partial = [];
6363
protected string $storageId;
64-
protected Storage $storageCache;
64+
protected ?Storage $storageCache = null;
6565
protected IMimeTypeLoader $mimetypeLoader;
6666
protected IDBConnection $connection;
6767
protected SystemConfig $systemConfig;
6868
protected LoggerInterface $logger;
6969
protected QuerySearchHelper $querySearchHelper;
7070
protected IEventDispatcher $eventDispatcher;
7171
protected IFilesMetadataManager $metadataManager;
72+
private CacheDependencies $cacheDependencies;
7273

7374
public function __construct(
7475
private IStorage $storage,
@@ -83,7 +84,7 @@ public function __construct(
8384
if (!$dependencies) {
8485
$dependencies = Server::get(CacheDependencies::class);
8586
}
86-
$this->storageCache = new Storage($this->storage, true, $dependencies->getConnection());
87+
$this->cacheDependencies = $dependencies;
8788
$this->mimetypeLoader = $dependencies->getMimeTypeLoader();
8889
$this->connection = $dependencies->getConnection();
8990
$this->systemConfig = $dependencies->getSystemConfig();
@@ -101,6 +102,9 @@ protected function getQueryBuilder() {
101102
}
102103

103104
public function getStorageCache(): Storage {
105+
if (!$this->storageCache) {
106+
$this->storageCache = new Storage($this->storage, true, $this->cacheDependencies->getConnection());
107+
}
104108
return $this->storageCache;
105109
}
106110

@@ -111,7 +115,7 @@ public function getStorageCache(): Storage {
111115
*/
112116
#[\Override]
113117
public function getNumericStorageId() {
114-
return $this->storageCache->getNumericId();
118+
return $this->getStorageCache()->getNumericId();
115119
}
116120

117121
/**

0 commit comments

Comments
 (0)