b5b80549ea
After every upload, maybe_update_storage_usage spawned a full `SUM(size) OVER all the user's non-trashed files` to refresh auth.users.storage_used_bytes — O(N) in the user's file count per upload, i.e. O(N²) for a bulk upload. (The covering index makes it index-only but still scans N rows.) Replace it with an O(1) incremental `storage_used_bytes += size`, keyed by the file's owner_id (dropping the brittle "My Folder - <user>" path-parsing hack). Deletes/trash never decremented this value — they already rely on the periodic reconciliation sweep — so the model is unchanged: the sweep remains the correctness backstop for every mutation, and the counter is clamped at 0. Both stay fire-and-forget on a background task, off the upload's latency path. Benchmarked (per-call, vs the user's existing file count N): N=1k: full-SUM 202us vs incremental 123us N=10k: full-SUM 1185us vs incremental 113us (10x) N=50k: full-SUM 5397us vs incremental 114us (47x — incremental is flat O(1)) Bulk upload of 10k files (insert + usage update each): full-SUM (O(N²)) 10.37s -> incremental (O(N)) 4.89s (>2x, diverges with scale) https://claude.ai/code/session_01DCszkkU11LYxMEUWr4setK