大量优化修改扣积分规则
This commit is contained in:
@@ -1248,6 +1248,7 @@ class FreeVideoUploadView(APIView):
|
||||
class ModelConfigViewSet(ReadOnlyModelViewSet):
|
||||
# 按创建序固定排序:最早创建的 active 模型排第一 = 前端选择器默认项,与 get_default_model 口径一致。
|
||||
# DeepSeek 已停用,下拉里不再出现。
|
||||
# 列表短且高频(创作页下拉),整页结果缓存;后台改模型走 invalidate_model_catalog_cache。
|
||||
queryset = (
|
||||
ModelConfig.objects.select_related("provider")
|
||||
.filter(status=ModelConfig.Status.ACTIVE)
|
||||
@@ -1259,6 +1260,30 @@ class ModelConfigViewSet(ReadOnlyModelViewSet):
|
||||
search_fields = ["name", "display_name", "capability"]
|
||||
ordering_fields = ["created_at", "display_name"]
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
from django.core.cache import cache
|
||||
|
||||
from apps.ai.model_catalog import MODEL_CATALOG_CACHE_KEY, MODEL_CATALOG_CACHE_TTL
|
||||
|
||||
# 缓存「无 search/ordering/capability、首页」目录。page_size=200 是创作页常规用法。
|
||||
qp = request.query_params
|
||||
page = str(qp.get("page") or "1")
|
||||
page_size = str(qp.get("page_size") or "")
|
||||
is_plain = (
|
||||
not any(qp.get(k) for k in ("search", "ordering", "capability"))
|
||||
and page in {"1", ""}
|
||||
and page_size in {"", "200"}
|
||||
)
|
||||
cache_key = MODEL_CATALOG_CACHE_KEY if page_size in {"", "200"} else f"{MODEL_CATALOG_CACHE_KEY}:{page_size}"
|
||||
if is_plain:
|
||||
cached = cache.get(cache_key)
|
||||
if cached is not None:
|
||||
return Response(cached)
|
||||
response = super().list(request, *args, **kwargs)
|
||||
if is_plain and response.status_code == 200:
|
||||
cache.set(cache_key, response.data, MODEL_CATALOG_CACHE_TTL)
|
||||
return response
|
||||
|
||||
|
||||
|
||||
class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
|
||||
|
||||
Reference in New Issue
Block a user