Skip to content

Commit e6fb192

Browse files
committed
perf: cache root cache entries for external storage in MountCacheService
Signed-off-by: Robin Appelman <[email protected]>
1 parent 4713202 commit e6fb192

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/files_external/lib/Service/MountCacheService.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Files_External\Event\StorageDeletedEvent;
1616
use OCA\Files_External\Event\StorageUpdatedEvent;
1717
use OCA\Files_External\Lib\StorageConfig;
18+
use OCP\Cache\CappedMemoryCache;
1819
use OCP\EventDispatcher\Event;
1920
use OCP\EventDispatcher\Event as T;
2021
use OCP\EventDispatcher\IEventListener;
@@ -35,13 +36,16 @@
3536
* @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|Event>
3637
*/
3738
class MountCacheService implements IEventListener {
39+
private CappedMemoryCache $storageRootCache;
40+
3841
public function __construct(
3942
private readonly IUserMountCache $userMountCache,
4043
private readonly ConfigAdapter $configAdapter,
4144
private readonly IUserManager $userManager,
4245
private readonly IGroupManager $groupManager,
4346
private readonly GlobalStoragesService $storagesService,
4447
) {
48+
$this->storageRootCache = new CappedMemoryCache();
4549
}
4650

4751
public function handle(Event $event): void {
@@ -128,11 +132,16 @@ public function registerUpdatedStorage(StorageConfig $oldStorage, StorageConfig
128132
}
129133

130134
private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICacheEntry {
131-
// todo: reuse these between users when possible
132135
$storage = $this->configAdapter->constructStorageForUser($user, $storage);
136+
137+
if ($cachedEntry = $this->storageRootCache->get($storage->getId())) {
138+
return $cachedEntry;
139+
}
140+
133141
$cache = $storage->getCache();
134142
$entry = $cache->get('');
135143
if ($entry) {
144+
$this->storageRootCache->set($storage->getId(), $entry);
136145
return $entry;
137146
}
138147

@@ -156,7 +165,9 @@ private function getCacheEntryForRoot(IUser $user, StorageConfig $storage): ICac
156165
];
157166
$data['fileid'] = $cache->insert('', $data);
158167

159-
return new CacheEntry($data);
168+
$entry = new CacheEntry($data);
169+
$this->storageRootCache->set($storage->getId(), $entry);
170+
return $entry;
160171
}
161172

162173
private function registerForUser(IUser $user, StorageConfig $storage): void {

0 commit comments

Comments
 (0)