Skip to content

feat(organisations): report measured usage, null for what cannot be measured - #4676

Merged
rubenvdlinde merged 4 commits into
developmentfrom
feat/organisation-usage-measured
Oct 17, 2026
Merged

rubenvdlinde merged 4 commits into
developmentfrom
feat/organisation-usage-measured

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What

An organisation's usage block reported storage, bandwidth and requests as a fixed 0, which reads as "nothing used". It now reports only what OpenRegister measures, and null for anything it cannot measure.

GET /api/organisations/{uuid} (after the existing hasAccessToOrganisation check) returns usage from the new OrganisationUsageService:

field value
users, groups Counts of the organisation's members and groups (unchanged)
storage Bytes: the summed file-cache size of the folders of the organisation's live objects, across every magic table (_organisation = uuid, _deleted null). null if the read fails.
requests This hour's counter kept by TenantQuotaMiddleware. That counter only exists for an organisation with a request quota and with APCu, so otherwise null. It is 0 only when counted and none were made.
bandwidth Always null. The middleware sums JSON response bodies only, which is not the organisation's bandwidth.

Everywhere else the entity is serialised (index, search, active), storage, bandwidth and requests are now null instead of 0, because the entity cannot measure them.

New helpers: MagicMapper::findFolderIdsByOrganisation() and FileMapper::sumSizesByFileIds() (chunked; unscanned entries with negative size are skipped).

OrganisationController gains a tenth constructor collaborator. It carries a PHPMD.ExcessiveParameterList suppression with a reason, the same pattern as 129 others in lib/.

Openspec change: organisation-usage-measured.

Verified

  • hydra/scripts/diff-check.sh --base origin/development: GREEN (0 NEW findings). The only findings are 1331 inherited phpcs findings in the existing test files whose constructor calls gained an argument.
  • New and changed tests:
    • OrganisationUsageServiceTest: 8 tests.
    • OrganisationControllerTest: show returns the measured usage, and a refused show measures nothing.
    • OrganisationTest: usage is null.
  • Without the lib change, the changed tests fail: testJsonSerializeUsageStructure and testShowReturnsMeasuredUsage fail, and the service tests error because the class is missing.
  • COMPOSER_PROCESS_TIMEOUT=0 composer check:strict:
    • lint, migration-version, phpcs, phpmd, psalm (no errors) and phpstan ([OK]) all pass.
    • test:all: 26295 tests, 0 failures, 15 errors. All 15 come from tests/Support/MigratedSqliteDatabase.php ("OC\DB\Schema\Table is not loadable") in audit-trail tests, which need an installed Nextcloud root. They fail identically on plain development.

Note for consumers

A client that shows usage.storage/requests should treat null as "not measured" (no bar), not as 0.

This PR was prepared with AI assistance (Claude Code) and reviewed by a human before merge.

🤖 Generated with Claude Code

…easured

The organisation usage block reported storage, bandwidth and requests as a
fixed 0. GET /api/organisations/{uuid} now measures storage (the file cache
size of the folders of the organisation's live objects) and requests (this
hour's quota-middleware counter, only when one is kept); users and groups
stay member counts. Anything not measured, including bandwidth and every
figure in lists, is null instead of 0.

Assisted-by: ClaudeCode:claude-opus-5-5
…elpers

Assisted-by: ClaudeCode:claude-opus-5-5
…n collaborators

Assisted-by: ClaudeCode:claude-opus-5-5
@rubenvdlinde
rubenvdlinde merged commit e890dcd into development Oct 17, 2026
39 checks passed
@rubenvdlinde
rubenvdlinde deleted the feat/organisation-usage-measured branch October 17, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant