Skip to content

v4.16.0 — The quota counts bytes that exist

Choose a tag to compare

@Alexandr-Paleev Alexandr-Paleev released this 21 Nov 07:01
c462a4f

The quota counts bytes that exist. The storage quota has lived in the database since 4.0: a trigger counts each file's size against the plan, under a lock, on every path. The size was the browser's word, though. The browser wrote the row, and an account could upload 40 MB and record a kilobyte. Now the size of a hosted file is read from where the file is.

  • Supabase Storage. When a row is written, the database reads its size from the object at its path. It refuses a row with nothing behind it, or one outside its owner's folder (migration 020).
  • Cloudinary and R2. Their rows are written only by /api/cloudinary/confirm and /api/r2/confirm. These ask the provider what it holds and write the row with the service role. A browser may no longer insert one. Over the quota, the object is deleted and the upload refused with 413, and the upload page says so as before.
  • The cost: an upload to Cloudinary or R2 is one request longer. Cloudinary's Admin API allows 500 such questions an hour on the free plan, one per upload.

See decision 0017.

What a row does not say is found at night. Once a day, Vercel Cron calls /api/account/reconcile, which holds each provider against the rows:

  • an object no row names is removed once it is a day old: an upload signed and never confirmed, or what an old account erase left;
  • a row whose size is not its object's gets the object's size (an object can be deleted and put again at the same path);
  • a row with no object is reported, never removed;
  • bytes_used is recounted from the rows, each profile locked first.

Migration 021 adds the two queries this needs and stops the quota trigger refusing an UPDATE, since only the reconciliation changes a size now.

It runs dry until RECONCILE_APPLY=true. It removes nothing when most of a provider has no row, or when rows and objects miss each other on the same night: that is what a misread looks like. What it finds goes to Sentry, in counts. On its first night on production it found and removed 8 Storage objects and 13 Cloudinary assets that no row named, 0.84 MB in all. See decision 0018.

api/account/delete.ts is now api/account/[action].ts, at the same address: the Hobby plan's twelve functions were all in use.

What it costs: the first load is 377.4 kB gzipped, as in 4.15.0; all assets are 472.9 kB, 0.3 kB more. The unit tests went from 1,831 to 1,936, and the site's stay at 74. The end-to-end suite passed 48 of 48 on each run on main since 4.15.0, none on a retry.