From eaa4058c56bad642b3be677d6c6f8bfff5c8ef9c Mon Sep 17 00:00:00 2001 From: wwq Date: Wed, 22 Apr 2026 14:12:44 +0800 Subject: [PATCH] fix(quota_manager): exclude trial users from tenant terminal user count - Deduct trial user records when aggregating the total number of terminal users for a tenant. --- api/app/core/quota_manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/app/core/quota_manager.py b/api/app/core/quota_manager.py index 534e1940..ad684eb9 100644 --- a/api/app/core/quota_manager.py +++ b/api/app/core/quota_manager.py @@ -179,11 +179,18 @@ class QuotaUsageRepository: def count_end_users(self, tenant_id: UUID) -> int: from app.models.end_user_model import EndUser from app.models.workspace_model import Workspace - return self.db.query(EndUser).join( + from app.models.user_model import User + trial_user_ids = [ + str(u.id) for u in self.db.query(User.id).filter(User.tenant_id == tenant_id).all() + ] + query = self.db.query(EndUser).join( Workspace, EndUser.workspace_id == Workspace.id ).filter( Workspace.tenant_id == tenant_id - ).count() + ) + if trial_user_ids: + query = query.filter(~EndUser.other_id.in_(trial_user_ids)) + return query.count() def count_models(self, tenant_id: UUID) -> int: from app.models.models_model import ModelConfig