From 7ced07d40295bc78bd8ef676d0d6b860f9a3c705 Mon Sep 17 00:00:00 2001 From: colaftc Date: Tue, 23 Dec 2025 16:12:11 +0800 Subject: [PATCH] feat: added cache to mdy_plate_staging api --- api_v1/views/mingdaoyun/plate_order_staging.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api_v1/views/mingdaoyun/plate_order_staging.py b/api_v1/views/mingdaoyun/plate_order_staging.py index c69f7d6..791d1da 100644 --- a/api_v1/views/mingdaoyun/plate_order_staging.py +++ b/api_v1/views/mingdaoyun/plate_order_staging.py @@ -11,6 +11,9 @@ from __future__ import annotations from typing import Any +from django.core.cache import cache +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page from django.db.models import F from rest_framework import serializers, viewsets from rest_framework.pagination import LimitOffsetPagination @@ -83,6 +86,7 @@ class MDYPlateOrderStagingSerializer(serializers.ModelSerializer): return out +@method_decorator(cache_page(10), name='list') class MDYPlateOrderStagingViewSet(viewsets.ReadOnlyModelViewSet): """开版暂存数据查询(只读)。""" @@ -100,3 +104,10 @@ class MDYPlateOrderStagingViewSet(viewsets.ReadOnlyModelViewSet): # 默认 -ctime;ctime 为空的放最后,避免老数据(未回填)跑到前面 return qs.order_by(F("ctime").desc(nulls_last=True), F("id").desc()) + + def filter_queryset(self, queryset): + qs = super().filter_queryset(queryset) + design_no = self.request.query_params.get(f"raw__{_PLATE_ORDER_DESIGN_NO_CONTROL_ID}") + if design_no: + qs = qs.filter(**{f"raw__{_PLATE_ORDER_DESIGN_NO_CONTROL_ID}": design_no}) + return qs