fix: speed up chat detail pagination
This commit is contained in:
@@ -3,7 +3,7 @@ from sqlalchemy.orm import Session
|
||||
from sqlalchemy.pool import StaticPool
|
||||
|
||||
from app.api.admin_agent_records import attention_list, retrieval_logs
|
||||
from app.api.admin_records import ai_logs, chat_detail
|
||||
from app.api.admin_records import ai_logs, chat_detail, chat_messages
|
||||
from app.api.admin_users import list_users
|
||||
from app.models import Base
|
||||
from app.models.chat import ChatMessage, ChatSession
|
||||
@@ -65,6 +65,27 @@ def test_chat_detail_messages_are_paginated():
|
||||
assert data["messages"][0]["content"] == "消息11"
|
||||
|
||||
|
||||
def test_chat_messages_endpoint_returns_only_message_page():
|
||||
with _database() as db:
|
||||
user = User(id=1, phone="13800000000", name="学员", daily_chat_limit=10)
|
||||
session = ChatSession(id=1, user_id=1, title="长会话", message_count=12)
|
||||
db.add_all([user, session])
|
||||
db.add_all([
|
||||
ChatMessage(id=index + 1, session_id=1, user_id=1, role="user", content=f"消息{index + 1}")
|
||||
for index in range(12)
|
||||
])
|
||||
db.add(AiRequestLog(session_id=1, status="success", prompt="p" * 5000, retrieved_chunks='[{"content":"large"}]'))
|
||||
db.commit()
|
||||
|
||||
response = chat_messages(1, page=2, pageSize=10, db=db, current_admin=object())
|
||||
|
||||
data = response["data"]
|
||||
assert data["total"] == 12
|
||||
assert len(data["items"]) == 2
|
||||
assert data["items"][0]["content"] == "消息11"
|
||||
assert "aiLogs" not in data
|
||||
|
||||
|
||||
def test_retrieval_and_attention_lists_are_paginated():
|
||||
with _database() as db:
|
||||
for index in range(21):
|
||||
|
||||
Reference in New Issue
Block a user