-
Notifications
You must be signed in to change notification settings - Fork 6
perf: Schedule deletion in chunks + Don't create Node objects in a loop #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c47d1ad
fix(FsEventService#onDelete): Schedule deletion in chunks
marcelklehr 60638d2
fix(StorageService#getAllFilesInFolder): Only return fileIds
marcelklehr a666b5c
fix(FsEventService): Add back allowedPath check
marcelklehr 53277dd
fix: Catch errors from Node->getId()
marcelklehr 124402f
fix(FsEventService): Batch call to ActionScheduler#deleteSources
marcelklehr 67cabef
fix(FsEventService): Add back mime type check for singular nodes
marcelklehr 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
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 |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |
| use OCA\ContextChat\Db\QueueFile; | ||
| use OCA\ContextChat\Logger; | ||
| use OCP\DB\Exception; | ||
| use OCP\Files\File; | ||
| use OCP\Files\Folder; | ||
| use OCP\Files\InvalidPathException; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\Files\Node; | ||
| use OCP\Files\NotFoundException; | ||
|
|
||
|
|
@@ -23,7 +25,7 @@ public function __construct( | |
| private QueueService $queue, | ||
| private ActionScheduler $actionService, | ||
| private StorageService $storageService, | ||
| private \OCP\Share\IManager $shareManager, | ||
| private IRootFolder $rootFolder, | ||
| ) { | ||
|
|
||
| } | ||
|
|
@@ -34,60 +36,55 @@ public function onAccessUpdateDecl(Node $node, bool $recurse = true): void { | |
| return; | ||
| } | ||
|
|
||
| $files = $this->storageService->getAllFilesInFolder($node); | ||
| $fileIds = $this->storageService->getAllFilesInFolder($node); | ||
| } else { | ||
| $files = [$node]; | ||
| } | ||
|
|
||
| foreach ($files as $file) { | ||
| if (!$this->allowedMimeType($file)) { | ||
| continue; | ||
| if (!$this->allowedMimeType($node)) { | ||
| return; | ||
| } | ||
| try { | ||
| $fileRef = ProviderConfigService::getSourceId($file->getId()); | ||
| $fileUserIds = $this->storageService->getUsersForFileId($file->getId()); | ||
|
|
||
| if (class_exists('OCP\Files\Config\Event\UserMountAddedEvent')) { | ||
| $userIds = $fileUserIds; | ||
| } else { | ||
| // todo: Remove this once we no longer support Nextcloud 31 | ||
| $shareAccessList = $this->shareManager->getAccessList($file, true, true); | ||
| /** @var string[] $shareUserIds */ | ||
| $shareUserIds = array_keys($shareAccessList['users']); | ||
| $userIds = array_values(array_unique(array_merge($shareUserIds, $fileUserIds))); | ||
| } | ||
|
|
||
| $this->actionService->updateAccessDeclSource($userIds, $fileRef); | ||
| $fileIds = [$node->getId()]; | ||
| } catch (InvalidPathException|NotFoundException $e) { | ||
| $this->logger->warning('Cannot get file id for declarative access update:' . $e->getMessage(), [ | ||
| 'exception' => $e | ||
| ]); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| foreach ($fileIds as $fileId) { | ||
| $fileRef = ProviderConfigService::getSourceId($fileId); | ||
| $fileUserIds = $this->storageService->getUsersForFileId($fileId); | ||
|
|
||
| $this->actionService->updateAccessDeclSource($fileUserIds, $fileRef); | ||
| } | ||
| } | ||
|
|
||
| public function onDelete(Node $node, bool $recurse = true): void { | ||
| if ($node instanceof Folder) { | ||
| if (!$recurse) { | ||
| return; | ||
| } | ||
| $files = $this->storageService->getAllFilesInFolder($node); | ||
| $fileIds = $this->storageService->getAllFilesInFolder($node); | ||
| } else { | ||
| $files = [$node]; | ||
| } | ||
|
|
||
| foreach ($files as $file) { | ||
| if (!$this->allowedMimeType($file)) { | ||
| continue; | ||
| if (!$this->allowedMimeType($node)) { | ||
| return; | ||
| } | ||
| try { | ||
| $fileIds = [$node->getId()]; | ||
| } catch (InvalidPathException|NotFoundException $e) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| $fileRefs = []; | ||
| foreach ($fileIds as $fileId) { | ||
| try { | ||
| $fileRef = ProviderConfigService::getSourceId($file->getId()); | ||
| $this->actionService->deleteSources($fileRef); | ||
| $fileRefs[] = ProviderConfigService::getSourceId($fileId); | ||
| } catch (InvalidPathException|NotFoundException $e) { | ||
| $this->logger->warning($e->getMessage(), ['exception' => $e]); | ||
| } | ||
| } | ||
| $batches = array_chunk($fileRefs, ActionScheduler::BATCH_SIZE); | ||
| foreach ($batches as $batch) { | ||
| $this->actionService->deleteSources($batch); | ||
| } | ||
| } | ||
|
|
||
| public function onInsert(Node $node, bool $recurse = true, bool $update = false): void { | ||
|
|
@@ -98,19 +95,26 @@ public function onInsert(Node $node, bool $recurse = true, bool $update = false) | |
| if (!$recurse) { | ||
| return; | ||
| } | ||
| $files = $this->storageService->getAllFilesInFolder($node); | ||
| $fileIds = $this->storageService->getAllFilesInFolder($node); | ||
| } else { | ||
| $files = [$node]; | ||
| if (!$this->allowedMimeType($node)) { | ||
| return; | ||
| } | ||
| try { | ||
| $fileIds = [$node->getId()]; | ||
| } catch (InvalidPathException|NotFoundException $e) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| foreach ($files as $file) { | ||
| if (!$this->allowedMimeType($file)) { | ||
|
Member
Author
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. getAllFilesInFolder checks mimetypes already |
||
| foreach ($fileIds as $fileId) { | ||
| $file = current($this->rootFolder->getById($fileId)); | ||
| if (!$file instanceof File) { | ||
| continue; | ||
| } | ||
| if (!$this->allowedPath($file)) { | ||
| continue; | ||
| } | ||
|
|
||
| $queueFile = new QueueFile(); | ||
| if ($file->getMountPoint()->getNumericStorageId() === null) { | ||
| return; | ||
|
|
||
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
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.
No more O(n) DB queries