1515use OCA \Files_External \Event \StorageDeletedEvent ;
1616use OCA \Files_External \Event \StorageUpdatedEvent ;
1717use OCA \Files_External \Lib \StorageConfig ;
18+ use OCP \Cache \CappedMemoryCache ;
1819use OCP \EventDispatcher \Event ;
1920use OCP \EventDispatcher \Event as T ;
2021use OCP \EventDispatcher \IEventListener ;
3536 * @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|Event>
3637 */
3738class 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