diff --git a/api/services/account_service.py b/api/services/account_service.py index 8362e415c1..0e699d16da 100644 --- a/api/services/account_service.py +++ b/api/services/account_service.py @@ -1041,6 +1041,8 @@ class TenantService: db.session.add(ta) db.session.commit() + if dify_config.BILLING_ENABLED: + BillingService.clean_billing_info_cache(tenant.id) return ta @staticmethod @@ -1199,6 +1201,9 @@ class TenantService: db.session.delete(ta) db.session.commit() + if dify_config.BILLING_ENABLED: + BillingService.clean_billing_info_cache(tenant.id) + @staticmethod def update_member_role(tenant: Tenant, member: Account, new_role: str, operator: Account): """Update member role""" diff --git a/api/services/app_service.py b/api/services/app_service.py index ab2b38ec01..d524adbf3e 100644 --- a/api/services/app_service.py +++ b/api/services/app_service.py @@ -20,6 +20,7 @@ from libs.login import current_user from models.account import Account from models.model import App, AppMode, AppModelConfig, Site from models.tools import ApiToolProvider +from services.billing_service import BillingService from services.enterprise.enterprise_service import EnterpriseService from services.feature_service import FeatureService from services.tag_service import TagService @@ -162,6 +163,9 @@ class AppService: # update web app setting as private EnterpriseService.WebAppAuth.update_app_access_mode(app.id, "private") + if dify_config.BILLING_ENABLED: + BillingService.clean_billing_info_cache(app.tenant_id) + return app def get_app(self, app: App) -> App: @@ -337,6 +341,9 @@ class AppService: if FeatureService.get_system_features().webapp_auth.enabled: EnterpriseService.WebAppAuth.cleanup_webapp(app.id) + if dify_config.BILLING_ENABLED: + BillingService.clean_billing_info_cache(app.tenant_id) + # Trigger asynchronous deletion of app and related data remove_app_and_related_data_task.delay(tenant_id=app.tenant_id, app_id=app.id) diff --git a/api/services/billing_service.py b/api/services/billing_service.py index a364862a88..9d6c5b4b31 100644 --- a/api/services/billing_service.py +++ b/api/services/billing_service.py @@ -5,6 +5,7 @@ import httpx from tenacity import retry, retry_if_exception_type, stop_before_delay, wait_fixed from extensions.ext_database import db +from extensions.ext_redis import redis_client from libs.helper import RateLimiter from models.account import Account, TenantAccountJoin, TenantAccountRole @@ -173,3 +174,7 @@ class BillingService: res = cls._send_request("POST", "/compliance/download", json=json) cls.compliance_download_rate_limiter.increment_rate_limit(limiter_key) return res + + @classmethod + def clean_billing_info_cache(cls, tenant_id: str): + redis_client.delete(f"tenant:{tenant_id}:billing_info")