From e61c1e1e6b901c6ee8a0bbd76fea9a02f4e52a65 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Fri, 13 Mar 2026 18:08:14 +0800 Subject: [PATCH] perf: license limit asset count --- apps/assets/api/asset/asset.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/assets/api/asset/asset.py b/apps/assets/api/asset/asset.py index 499187a9c..5a25fea1d 100644 --- a/apps/assets/api/asset/asset.py +++ b/apps/assets/api/asset/asset.py @@ -33,8 +33,16 @@ __all__ = [ def get_license_asset_limit(): - license_info = getattr(settings, 'XPACK_LICENSE_INFO', {}) or {} - return license_info.get('license', {}).get('count') or 0 + if not settings.XPACK_ENABLED: + return 0 + + try: + from xpack.models import License + except ImportError: + return 0 + + detail = License.get_license_detail() or {} + return detail.get('asset_count', 0) class AssetFilterSet(BaseFilterSet): @@ -166,7 +174,7 @@ class BaseAssetViewSet(OrgBulkModelViewSet): if settings.XPACK_LICENSE_IS_VALID: license_asset_limit = get_license_asset_limit() - if license_asset_limit and asset_count >= license_asset_limit: + if asset_count >= license_asset_limit: error = _('The number of assets exceeds the license limit') return Response({'error': error}, status=400)