-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add interface to allow "more direct" access to the filecache without direct db #44044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
576a554
feat: add interface for lower level filecache acess without having to…
icewind1991 cb580ad
refactor: don't join on filecache in usermountcache
icewind1991 2ce83d8
refactor: remove non-shallow getSharesInFolder
icewind1991 015988b
refactor: don't join on filecache in defaultshareprovider
icewind1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,11 @@ | |
| */ | ||
| namespace OCA\Files_Sharing; | ||
|
|
||
| use OC\Files\Cache\FileAccess; | ||
| use OC\Files\Mount\MountPoint; | ||
| use OCP\Constants; | ||
| use OCP\Files\Folder; | ||
| use OCP\Server; | ||
| use OCP\Share\IShare; | ||
|
|
||
| class Updater { | ||
|
|
@@ -58,20 +60,40 @@ private static function moveShareInOrOutOfShare($path): void { | |
| if ($userFolder === null) { | ||
| return; | ||
| } | ||
| $user = $userFolder->getOwner(); | ||
| if (!$user) { | ||
| throw new \Exception("user folder has no owner"); | ||
| } | ||
|
|
||
| $src = $userFolder->get($path); | ||
|
|
||
| $shareManager = \OC::$server->getShareManager(); | ||
|
|
||
| // FIXME: should CIRCLES be included here ?? | ||
| $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); | ||
| $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); | ||
| $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); | ||
| $shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1); | ||
| $shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1)); | ||
| $shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1)); | ||
|
|
||
| if ($src instanceof Folder) { | ||
| $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false); | ||
| $cacheAccess = Server::get(FileAccess::class); | ||
|
|
||
| $sourceStorageId = $src->getStorage()->getCache()->getNumericStorageId(); | ||
| $sourceInternalPath = $src->getInternalPath(); | ||
| $subShares = array_merge( | ||
| $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER), | ||
| $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP), | ||
| $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM), | ||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did the |
||
| ); | ||
| $shareSourceIds = array_map(fn (IShare $share) => $share->getNodeId(), $subShares); | ||
| $shareSources = $cacheAccess->getByFileIdsInStorage($shareSourceIds, $sourceStorageId); | ||
|
||
| foreach ($subShares as $subShare) { | ||
| $shares = array_merge($shares, array_values($subShare)); | ||
| $shareCacheEntry = $shareSources[$subShare->getNodeId()] ?? null; | ||
| if ( | ||
| $shareCacheEntry && | ||
|
||
| str_starts_with($shareCacheEntry->getPath(), $sourceInternalPath . '/') | ||
| ) { | ||
| $shares[] = $subShare; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| namespace OC\Files\Cache; | ||
|
|
||
| use OC\FilesMetadata\FilesMetadataManager; | ||
| use OC\SystemConfig; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\Files\Cache\IFileAccess; | ||
| use OCP\Files\IMimeTypeLoader; | ||
| use OCP\IDBConnection; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** | ||
| * Lower level access to the file cache | ||
| */ | ||
| class FileAccess implements IFileAccess { | ||
| public function __construct( | ||
| private IDBConnection $connection, | ||
| private SystemConfig $systemConfig, | ||
| private LoggerInterface $logger, | ||
| private FilesMetadataManager $metadataManager, | ||
| private IMimeTypeLoader $mimeTypeLoader, | ||
| ) { | ||
| } | ||
|
|
||
| private function getQuery(): CacheQueryBuilder { | ||
| return new CacheQueryBuilder( | ||
| $this->connection, | ||
| $this->systemConfig, | ||
| $this->logger, | ||
| $this->metadataManager, | ||
| ); | ||
| } | ||
|
|
||
| public function getByFileIdInStorage(int $fileId, int $storageId): ?CacheEntry { | ||
| $items = $this->getByFileIdsInStorage([$fileId], $storageId); | ||
| return (count($items) > 0) ? $items[0] : null; | ||
| } | ||
|
|
||
| public function getByPathInStorage(string $path, int $storageId): ?CacheEntry { | ||
| $query = $this->getQuery()->selectFileCache(); | ||
| $query->andWhere($query->expr()->eq('filecache.path_hash', $query->createNamedParameter(md5($path)))); | ||
| $query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); | ||
|
|
||
| $row = $query->executeQuery()->fetch(); | ||
| return $row ? Cache::cacheEntryFromData($row, $this->mimeTypeLoader) : null; | ||
| } | ||
|
|
||
| public function getByFileId(int $fileId): ?CacheEntry { | ||
| $items = $this->getByFileIds([$fileId]); | ||
| return (count($items) > 0) ? $items[0] : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param array[] $rows | ||
| * @return array<int, CacheEntry> | ||
| */ | ||
| private function rowsToEntries(array $rows): array { | ||
| $result = []; | ||
| foreach ($rows as $row) { | ||
| $entry = Cache::cacheEntryFromData($row, $this->mimeTypeLoader); | ||
| $result[$entry->getId()] = $entry; | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * @param int[] $fileIds | ||
| * @return array<int, CacheEntry> | ||
| */ | ||
| public function getByFileIds(array $fileIds): array { | ||
| $query = $this->getQuery()->selectFileCache(); | ||
| $query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); | ||
|
|
||
| $rows = $query->executeQuery()->fetchAll(); | ||
| return $this->rowsToEntries($rows); | ||
| } | ||
|
|
||
| /** | ||
| * @param int[] $fileIds | ||
| * @param int $storageId | ||
| * @return array<int, CacheEntry> | ||
| */ | ||
| public function getByFileIdsInStorage(array $fileIds, int $storageId): array { | ||
| $fileIds = array_values($fileIds); | ||
| $query = $this->getQuery()->selectFileCache(); | ||
| $query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); | ||
| $query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); | ||
|
|
||
| $rows = $query->executeQuery()->fetchAll(); | ||
| return $this->rowsToEntries($rows); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change about?