Skip to content

Add per-user storage view#40477

Closed
pako81 wants to merge 9 commits intoowncloud:masterfrom
pako81:add_per_user_storage
Closed

Add per-user storage view#40477
pako81 wants to merge 9 commits intoowncloud:masterfrom
pako81:add_per_user_storage

Conversation

@pako81
Copy link
Copy Markdown

@pako81 pako81 commented Nov 7, 2022

Description

Add per-user storage view

Related Issue

Motivation and Context

Make possible to visualise used storage on per-user basis

How Has This Been Tested?

  • Access ~/settings/users URL. A new column Storage Used will display the amount of used storage for every user. This option can be also opted in/out under Settings in order to align with all other available users' options.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised
  • Changelog item

@pako81 pako81 added this to the development milestone Nov 7, 2022
@pako81 pako81 self-assigned this Nov 7, 2022
@owncloud owncloud deleted a comment from update-docs Bot Nov 11, 2022
Comment thread settings/Controller/UsersController.php Outdated
Comment thread settings/Controller/UsersController.php Outdated
\OC_Util::tearDownFS();
\OC_Util::setupFS($user->getUID());
$storage = \OC_Helper::getStorageInfo('/');
$storageUsed = sprintf("%d MB", $storage['used'] / 1024 / 1024);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this will return an integer value, so instead of 3.45 MB it will return 3 MB. \sprint('%.2f MB', .....) might be better because it will round the division to 2 decimals.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have rounded it to 1 decimal since the personal setting page is doing the same You are using 4.1 MB of 10 MB (41.35 %), so we should align?

Comment thread settings/Controller/UsersController.php Outdated
\OC_Util::setupFS($user->getUID());
$storage = \OC_Helper::getStorageInfo('/');
$storageUsed = sprintf("%d MB", $storage['used'] / 1024 / 1024);
} catch (\Exception $ex) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will require a log entry, specially because the 0 MB storage should be rare. We don't expect users without any file, so a 0 MB storage would means that something has happened, and in this case we must know what happened.
Also note that we're catching all the exceptions. We should catch only specific exceptions that we know it could happen and we know how to handle them. If we have to catch any exception, it's important to know what's going on. We might think we're catching an storageNotAvailable exception, but in fact, we might hiding a different exception, so troubleshooting will be harder.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added log entry, not sure however if this is enough based on your comment above.

@jvillafanez
Copy link
Copy Markdown
Member

We probably need to restore the FS of the initial user after the formatUserForIndex loop unless there is no risk of leaving the FS of a random user there.
In addition, I think it should be documented in the method. The method doesn't have any hint about changing the FS of the user, so it might be unexpected.
Other than that, the code looks good

@ownclouders
Copy link
Copy Markdown
Contributor

ownclouders commented Nov 11, 2022

💥 Acceptance tests pipeline webUILogin-chrome-mariadb10.2-php7.4 failed. The build has been cancelled.

https://drone.owncloud.com/owncloud/core/37254/125

@pako81
Copy link
Copy Markdown
Author

pako81 commented Nov 11, 2022

@jvillafanez done. Not sure this is enough.

Comment thread settings/Controller/UsersController.php Outdated
$this->log->error("Can't compute used storage for user " . $user->getUID() . ": " . $e->getMessage(), ['app' => 'settings']);
$storageUsed = "0 MB";
} finally {
\OC_Util::tearDownFS();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems the wrong place. Taking into account that this is a private function (can't be called from outside), the method is called at the end (chance of breaking things due to using the wrong user's FS is fairly low) and it's in a controller (there shouldn't be any code needed to access the FS after this), we could just ignore this and include some comments to warn that this method will setup a different FS.

@jvillafanez
Copy link
Copy Markdown
Member

Is it worthy to create a helper method somewhere in order to get the size of the root folder of the user's home without setting up a different FS? It seems less risky and there should be less overhead.
We're likely need to deal with buckets of 200 users, and I'm not sure how well this solution will perform taking into account that we need to setup each of the user's FS.

@pako81
Copy link
Copy Markdown
Author

pako81 commented Nov 15, 2022

@jvillafanez we can try, however I can see that i.e. the metrics app is doing the same https://github.com/owncloud/metrics/blob/master/lib/Metrics/QuotaMetrics.php#L62

@jvillafanez
Copy link
Copy Markdown
Member

Ok, then I think we just add some comments to warn that we're changing the FS user and we aren't reverting it back, at least for now. That should be good enough to finish this PR.

@pako81 pako81 closed this by deleting the head repository Nov 22, 2022
@pako81 pako81 mentioned this pull request Nov 22, 2022
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants