3131use OCP \SystemTag \TagNotFoundException ;
3232use OCP \WorkflowEngine \ICheck ;
3333use OCP \WorkflowEngine \IFileCheck ;
34+ use OC \Files \Storage \Wrapper \Wrapper ;
3435
3536class FileSystemTags implements ICheck, IFileCheck {
3637 use TFileCheck;
@@ -127,13 +128,26 @@ protected function getSystemTags() {
127128 * @return int[]
128129 */
129130 protected function getFileIds (ICache $ cache , $ path , $ isExternalStorage ) {
130- // TODO: Fix caching inside group folders
131- // Do not cache file ids inside group folders because multiple file ids might be mapped to
132- // the same combination of cache id + path.
133131 /** @psalm-suppress InvalidArgument */
134- $ shouldCacheFileIds = !$ this ->storage ->instanceOfStorage (\OCA \GroupFolders \Mount \GroupFolderStorage::class);
135- $ cacheId = $ cache ->getNumericStorageId ();
136- if ($ shouldCacheFileIds && isset ($ this ->fileIds [$ cacheId ][$ path ])) {
132+ if ($ this ->storage ->instanceOfStorage (\OCA \GroupFolders \Mount \GroupFolderStorage::class)) {
133+ // Special implementation for groupfolder since all groupfolders share the same storage
134+ // id so add the group folder id in the cache key too.
135+ $ groupFolderStorage = $ this ->storage ;
136+ if ($ this ->storage instanceof Wrapper) {
137+ $ groupFolderStorage = $ this ->storage ->getInstanceOfStorage (\OCA \GroupFolders \Mount \GroupFolderStorage::class);
138+ }
139+ if ($ groupFolderStorage === null ) {
140+ throw new \LogicException ('Should not happen: Storage is instance of GroupFolderStorage but no group folder storage found while unwrapping. ' );
141+ }
142+ /**
143+ * @psalm-suppress UndefinedDocblockClass
144+ * @psalm-suppress UndefinedInterfaceMethod
145+ */
146+ $ cacheId = $ cache ->getNumericStorageId () . '/ ' . $ groupFolderStorage ->getFolderId ();
147+ } else {
148+ $ cacheId = $ cache ->getNumericStorageId ();
149+ }
150+ if (isset ($ this ->fileIds [$ cacheId ][$ path ])) {
137151 return $ this ->fileIds [$ cacheId ][$ path ];
138152 }
139153
@@ -146,12 +160,10 @@ protected function getFileIds(ICache $cache, $path, $isExternalStorage) {
146160
147161 $ fileId = $ cache ->getId ($ path );
148162 if ($ fileId !== -1 ) {
149- $ parentIds [] = $ cache -> getId ( $ path ) ;
163+ $ parentIds [] = $ fileId ;
150164 }
151165
152- if ($ shouldCacheFileIds ) {
153- $ this ->fileIds [$ cacheId ][$ path ] = $ parentIds ;
154- }
166+ $ this ->fileIds [$ cacheId ][$ path ] = $ parentIds ;
155167
156168 return $ parentIds ;
157169 }
0 commit comments