collab: Adjust maximum spending limit check (#25596)

This is a follow-up to https://github.com/zed-industries/zed/pull/25573.

We were still using the spend for a particular model when determining if
the user was over their maximum monthly spend instead of looking at the
usage across all models.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-02-25 16:45:01 -05:00 committed by GitHub
parent 0066071a89
commit 7f166298db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -453,10 +453,6 @@ async fn check_usage_limit(
let user_id = UserId::from_proto(claims.user_id);
let model = state.db.model(provider, model_name)?;
let usage = state
.db
.get_usage(user_id, provider, model_name, Utc::now())
.await?;
let free_tier = claims.free_tier_monthly_spending_limit();
let spending_this_month = state
@ -471,7 +467,8 @@ async fn check_usage_limit(
));
}
if (usage.spending_this_month - free_tier) >= Cents(claims.max_monthly_spend_in_cents) {
let monthly_spend = spending_this_month.saturating_sub(free_tier);
if monthly_spend >= Cents(claims.max_monthly_spend_in_cents) {
return Err(Error::Http(
StatusCode::FORBIDDEN,
"Maximum spending limit reached for this month.".to_string(),
@ -496,6 +493,11 @@ async fn check_usage_limit(
model.max_tokens_per_minute as usize / users_in_recent_minutes;
let per_user_max_tokens_per_day = model.max_tokens_per_day as usize / users_in_recent_days;
let usage = state
.db
.get_usage(user_id, provider, model_name, Utc::now())
.await?;
let checks = [
(
usage.requests_this_minute,