From 4da2b028164a2ec5a48e96f3559aa5ab93479d4c Mon Sep 17 00:00:00 2001 From: "liuchangsheng@wisdomidata.com" Date: Wed, 25 Jun 2025 19:30:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Dify=E3=80=91=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=EF=BC=8C=E5=A4=A7=E6=95=B0=E6=8D=AE=E8=BF=94=E5=9B=9E=E6=85=A2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8E=BB=E6=8E=89=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/console/explore/message.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/controllers/console/explore/message.py b/api/controllers/console/explore/message.py index 822777604a..46aa3fdc1b 100644 --- a/api/controllers/console/explore/message.py +++ b/api/controllers/console/explore/message.py @@ -1,5 +1,6 @@ import logging +from flask import jsonify from flask_login import current_user from flask_restful import marshal_with, reqparse from flask_restful.inputs import int_range @@ -34,7 +35,9 @@ from services.message_service import MessageService class MessageListApi(InstalledAppResource): - @marshal_with(message_infinite_scroll_pagination_fields) + + # 解决数据较大,系列化过慢的问题 + # @marshal_with(message_infinite_scroll_pagination_fields) def get(self, installed_app): app_model = installed_app.app @@ -47,11 +50,20 @@ class MessageListApi(InstalledAppResource): parser.add_argument("first_id", type=uuid_value, location="args") parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args") args = parser.parse_args() - try: - return MessageService.pagination_by_first_id( + data = MessageService.pagination_by_first_id( app_model, current_user, args["conversation_id"], args["first_id"], args["limit"] ) + # 解决数据较大,系列化过慢的问题 + items = [] + if data.data: + items = [m.to_dict() for m in data.data] + return jsonify({ + 'data': items, # 假设分页对象里包含 items 列表 + "limit": data.limit, + 'has_more': data.has_more, + }) + # return data except services.errors.conversation.ConversationNotExistsError: raise NotFound("Conversation Not Exists.") except services.errors.message.FirstMessageNotExistsError: