perf(billing): compute usage balances once per limit check DEV-926 - #7637
Merged
Merged
Conversation
…ks DEV-926 Add check_exceeded_limits to check multiple usage types in one pass, computing balances lazily and accepting caller-provided balances. The submission rejection path now passes the balances it already computed instead of triggering a second full usage recomputation. check_exceeded_limit becomes a thin wrapper over the plural function.
Contributor
Author
Contributor
|
platreth
marked this pull request as ready for review
September 25, 2026 05:23
Guitlle
self-requested a review
September 25, 2026 16:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📣 Summary
Checking whether a project owner is over their plan limit now does less repeated work in some submission paths.
📖 Description
When a submission comes in, the server checks whether the project owner is over their submission or storage limit. Some paths, like imports and backups, worked out the owner's usage more than once for the same check. They now do it once. Which submissions get accepted or refused stays the same.
💭 Notes
check_exceeded_limits(user, usage_types)checks several usage types in one call and computes fresh balances at most once, only when a type gets past its 15-min gate.check_exceeded_limitstays as a thin wrapper for the NLP trackers and LRM 0011.@cache_for_requestalready deduplicated the two calls, so nothing changes there. Outside a request (imports, backups, briefcase) that memo does nothing, and main computes twice.test_over_limit_rejection_counts_on_fresh_usagecovers it.👀 Preview steps
Backend only. Watch how many times usage gets computed for one refused submission outside a web request.
test_check_exceeded_limits_computes_balances_onceandtest_over_limit_rejection_counts_on_fresh_usagecover it