Skip to content

Commit 88774cf

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
Optimize FileSystemTags workflow for groupfolder
In #28774 we disabled the caching for the groupfolder application since it worked due to the fact that in groupfolders, getFileIds could be called with the same $cacheId and path for actually different groupfolders. This revert this change and instead add the folderId from the groupFolder to the cacheId. This solve the issue of the uniqueness of the cacheId inside GroupFolder. Downside is that we introduce groupfolder specific implementation inside the server repo. The seconf optimization is to not consider paths starting with __groupfolders in executeCheck. This is due to the fact that files in the groupfolder application call two times executeCheck one time with the url __groupfolder/<folderId>/<path> and the other time with <path>. The first time will always return an empty systemTags array while the second call will return the correct system tags. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 3bdd8ae commit 88774cf

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

apps/workflowengine/lib/Check/FileSystemTags.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCP\SystemTag\TagNotFoundException;
3737
use OCP\WorkflowEngine\ICheck;
3838
use OCP\WorkflowEngine\IFileCheck;
39+
use OC\Files\Storage\Wrapper\Wrapper;
3940

4041
class FileSystemTags implements ICheck, IFileCheck {
4142
use TFileCheck;
@@ -72,6 +73,11 @@ public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISyst
7273
* @return bool
7374
*/
7475
public function executeCheck($operator, $value) {
76+
if (str_starts_with($this->path, '__groupfolders')) {
77+
// System tags are always empty in this case and executeCheck is called
78+
// a second time with the jailedPath
79+
return false;
80+
}
7581
$systemTags = $this->getSystemTags();
7682
return ($operator === 'is') === in_array($value, $systemTags);
7783
}
@@ -132,13 +138,29 @@ protected function getSystemTags() {
132138
* @return int[]
133139
*/
134140
protected function getFileIds(ICache $cache, $path, $isExternalStorage) {
135-
// TODO: Fix caching inside group folders
136-
// Do not cache file ids inside group folders because multiple file ids might be mapped to
137-
// the same combination of cache id + path.
138141
/** @psalm-suppress InvalidArgument */
139-
$shouldCacheFileIds = !$this->storage->instanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class);
140-
$cacheId = $cache->getNumericStorageId();
141-
if ($shouldCacheFileIds && isset($this->fileIds[$cacheId][$path])) {
142+
if ($this->storage->instanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class)) {
143+
static $groupFolderStorage = null;
144+
if ($groupFolderStorage === null) {
145+
// Special implementation for groupfolder since all groupfolder chare the same storage
146+
// so add the group folder id in the cache key too.
147+
$groupFolderStorage = $this->storage;
148+
$groupFolderStoragClass = \OCA\GroupFolders\Mount\GroupFolderStorage::class;
149+
while ($groupFolderStorage->instanceOfStorage(Wrapper::class)) {
150+
if ($groupFolderStorage instanceof $groupFolderStoragClass) {
151+
break;
152+
}
153+
/**
154+
* @var Wrapper $sourceStorage
155+
*/
156+
$groupFolderStorage = $groupFolderStorage->getWrapperStorage();
157+
}
158+
}
159+
$cacheId = $cache->getNumericStorageId() . '/' . $groupFolderStorage->getFolderId();
160+
} else {
161+
$cacheId = $cache->getNumericStorageId();
162+
}
163+
if (isset($this->fileIds[$cacheId][$path])) {
142164
return $this->fileIds[$cacheId][$path];
143165
}
144166

@@ -154,9 +176,7 @@ protected function getFileIds(ICache $cache, $path, $isExternalStorage) {
154176
$parentIds[] = $cache->getId($path);
155177
}
156178

157-
if ($shouldCacheFileIds) {
158-
$this->fileIds[$cacheId][$path] = $parentIds;
159-
}
179+
$this->fileIds[$cacheId][$path] = $parentIds;
160180

161181
return $parentIds;
162182
}

0 commit comments

Comments
 (0)