Skip to content

Conversation

@CarlSchwan
Copy link
Member

Summary

  • Use modern node and SetupManager API
  • Avoid passing the user by id and instead use IUser

Originally tried to optimize a bit the number of query but the new code is doing exactly as many DB request as before :( Still a nice cleanup

Checklist

@CarlSchwan CarlSchwan added this to the Nextcloud 33 milestone Sep 4, 2025
@CarlSchwan CarlSchwan self-assigned this Sep 4, 2025
@CarlSchwan CarlSchwan added 2. developing Work in progress ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) labels Sep 4, 2025
- Use modern node and SetupManager API
- Avoid passing the user by id and instead use IUser

Signed-off-by: Carl Schwan <[email protected]>
@CarlSchwan CarlSchwan force-pushed the carl/cleanup-commands-trash branch from bf64f65 to 63de669 Compare September 11, 2025 15:02
@CarlSchwan CarlSchwan requested a review from artonge September 11, 2025 15:03
@CarlSchwan CarlSchwan marked this pull request as ready for review September 11, 2025 15:04
@CarlSchwan CarlSchwan requested a review from a team as a code owner September 11, 2025 15:04
@CarlSchwan CarlSchwan requested review from Altahrim and sorbaugh and removed request for a team September 11, 2025 15:04
private LoggerInterface $logger,
private ?IUserManager $userManager = null,
private ?Expiration $expiration = null,
readonly private LoggerInterface $logger,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly private LoggerInterface $logger,
private readonly LoggerInterface $logger,

Same for the others

/** @var Folder $folder */
$folder = $this->rootFolder->getUserFolder($user->getUID())->getParent()->get('files_trashbin');
return $folder;
} catch (NotFoundException|NotPermittedException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be caught? If you let it bubble up it will get logged. But I’m not sure whether it should get logged. NotFound would just mean the user trashbin was not used yes.
NotPermitted maybe we should log.

} elseif (!empty($users)) {
foreach ($users as $user) {
if ($this->userManager->userExists($user)) {
$userObject = $this->userManager->get($user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather rename $users and $user to $userIds and $userId as it would be even less confusing. But that's a nitpick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strong type in the constructor?

Comment on lines +52 to +53
$setupManager = Server::get(SetupManager::class);
$rootFolder = Server::get(IRootFolder::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use DI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants