Skip to content

[PB-6472]: feat/track-user-mail-usage#220

Draft
jzunigax2 wants to merge 1 commit into
feat/mail-bucket-provisioningfrom
feat/track-user-mail-usage
Draft

[PB-6472]: feat/track-user-mail-usage#220
jzunigax2 wants to merge 1 commit into
feat/mail-bucket-provisioningfrom
feat/track-user-mail-usage

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jun 3, 2026

Copy link
Copy Markdown

What

Adds a usedSpaceBytes field to buckets and a gateway endpoint for setting it: PUT /v2/gateway/users/:uuid/buckets/:id/usage

Mail provisions one bucket per mail account #221 and periodically reports that account's usage from Stalwart here.

Why

Bridge needs to track each user's mail storage usage next to their Drive usage so the two can be checked against a single quota. Per review feedback: the bucket is the right entity to carry used space. Per review feedback: the bucket is the right entity to carry used space

How

  • usedSpaceBytes added to the bucket domain type and mongoose schema (default 0).
  • BucketsRepository.setUsedSpaceBytes(bucketId, userId, value): a single atomic updateOne filtered on _id + owner uuid; reports whether a document matched.
  • UsersUsecase.setBucketUsage: throws BucketNotFoundError when nothing matched
  • Gateway controller validates the bucket id shape (24-hex ObjectId) and that usedSpaceBytes is a non-negative finite number; JWT-protected like the rest of the gateway.

@jzunigax2 jzunigax2 added the enhancement New feature or request label Jun 3, 2026
@jzunigax2 jzunigax2 self-assigned this Jun 3, 2026
@jzunigax2 jzunigax2 changed the title feat/track-user-mail-usage [PB-6472]: feat/track-user-mail-usage Jun 5, 2026
@sg-gs

sg-gs commented Jun 5, 2026

Copy link
Copy Markdown
Member

The totalUsedSpaceBytes was a convenience field as an aggregation of everything. I find buckets the entity more suitable to have the same field or a similar one and relate all the content generated by mail to a specific bucket in the network, the same way we do with Drive and Backups' content.

This makes the network less coupled to mail/drive/any product we may release in the future that consumes space while gaining standarisation of the calculus of the used space on a bucket. WDYT @apsantiso @jzunigax2 ?

This may be even useful for Photos or the same Drive in any foreseeable future.

Add a usedSpaceBytes field to buckets and a gateway endpoint to set it, so products whose content lives outside the network (mail/Stalwart) can report the space they consume against a network bucket.
@jzunigax2 jzunigax2 force-pushed the feat/track-user-mail-usage branch from 02b5882 to 6f17e6b Compare June 9, 2026 20:03
@jzunigax2 jzunigax2 changed the base branch from master to feat/mail-bucket-provisioning June 9, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants