From d2a32c363d73e076a6af99192201a600d5e8b262 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Mon, 28 Apr 2025 18:19:15 +0800 Subject: [PATCH] perf: chat log list (#4704) * perf: chat log list * remove log --- .../zh-cn/docs/development/upgrading/498.md | 1 + .../dashboard/apps/JsonImportModal.tsx | 4 +- .../app/src/pages/api/core/app/getChatLogs.ts | 107 +++--------------- projects/app/src/web/context/useInitApp.ts | 1 + 4 files changed, 21 insertions(+), 92 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/498.md b/docSite/content/zh-cn/docs/development/upgrading/498.md index 01865adef..613262428 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/498.md +++ b/docSite/content/zh-cn/docs/development/upgrading/498.md @@ -14,6 +14,7 @@ weight: 792 ## ⚙️ 优化 +1. Chat log list 优化,避免大数据时超出内存限制。 ## 🐛 修复 diff --git a/projects/app/src/pageComponents/dashboard/apps/JsonImportModal.tsx b/projects/app/src/pageComponents/dashboard/apps/JsonImportModal.tsx index 3a94ee4c1..268c33acc 100644 --- a/projects/app/src/pageComponents/dashboard/apps/JsonImportModal.tsx +++ b/projects/app/src/pageComponents/dashboard/apps/JsonImportModal.tsx @@ -134,9 +134,7 @@ const JsonImportModal = ({ onClose }: { onClose: () => void }) => { onSuccess(id: string) { router.push(`/app/detail?appId=${id}`); loadMyApps(); - onClose(); - removeUtmParams(); - removeUtmWorkflow(); + handleCloseJsonImportModal(); }, successToast: t('common:common.Create Success') } diff --git a/projects/app/src/pages/api/core/app/getChatLogs.ts b/projects/app/src/pages/api/core/app/getChatLogs.ts index 84c82af32..f690f1cd1 100644 --- a/projects/app/src/pages/api/core/app/getChatLogs.ts +++ b/projects/app/src/pages/api/core/app/getChatLogs.ts @@ -74,108 +74,37 @@ async function handler( } } }, - { $count: 'messageCount' } - ], - as: 'messageCountData' - } - }, - { - $lookup: { - from: ChatItemCollectionName, - let: { chatId: '$chatId', appId: new Types.ObjectId(appId) }, - pipeline: [ { - $match: { - $expr: { - $and: [ - { $eq: ['$appId', '$$appId'] }, - { $eq: ['$chatId', '$$chatId'] }, - { $eq: ['$userGoodFeedback', true] } - ] - } + $group: { + _id: null, + messageCount: { $sum: 1 }, + goodFeedback: { $sum: { $cond: [{ $eq: ['$userGoodFeedback', true] }, 1, 0] } }, + badFeedback: { $sum: { $cond: [{ $eq: ['$userBadFeedback', true] }, 1, 0] } }, + customFeedback: { + $sum: { + $cond: [{ $gt: [{ $size: { $ifNull: ['$customFeedbacks', []] } }, 0] }, 1, 0] + } + }, + adminMark: { $sum: { $cond: [{ $eq: ['$adminFeedback', true] }, 1, 0] } } } - }, - { $count: 'count' } + } ], - as: 'userGoodFeedbackData' - } - }, - { - $lookup: { - from: ChatItemCollectionName, - let: { chatId: '$chatId', appId: new Types.ObjectId(appId) }, - pipeline: [ - { - $match: { - $expr: { - $and: [ - { $eq: ['$appId', '$$appId'] }, - { $eq: ['$chatId', '$$chatId'] }, - { $eq: ['$userBadFeedback', true] } - ] - } - } - }, - { $count: 'count' } - ], - as: 'userBadFeedbackData' - } - }, - { - $lookup: { - from: ChatItemCollectionName, - let: { chatId: '$chatId', appId: new Types.ObjectId(appId) }, - pipeline: [ - { - $match: { - $expr: { - $and: [ - { $eq: ['$appId', '$$appId'] }, - { $eq: ['$chatId', '$$chatId'] }, - { $gt: [{ $size: { $ifNull: ['$customFeedbacks', []] } }, 0] } - ] - } - } - }, - { $count: 'count' } - ], - as: 'customFeedbacksData' - } - }, - { - $lookup: { - from: ChatItemCollectionName, - let: { chatId: '$chatId', appId: new Types.ObjectId(appId) }, - pipeline: [ - { - $match: { - $expr: { - $and: [ - { $eq: ['$appId', '$$appId'] }, - { $eq: ['$chatId', '$$chatId'] }, - { $eq: ['$adminFeedback', true] } - ] - } - } - }, - { $count: 'count' } - ], - as: 'markData' + as: 'chatItemsData' } }, { $addFields: { + messageCount: { $ifNull: [{ $arrayElemAt: ['$chatItemsData.messageCount', 0] }, 0] }, userGoodFeedbackCount: { - $ifNull: [{ $arrayElemAt: ['$userGoodFeedbackData.count', 0] }, 0] + $ifNull: [{ $arrayElemAt: ['$chatItemsData.goodFeedback', 0] }, 0] }, userBadFeedbackCount: { - $ifNull: [{ $arrayElemAt: ['$userBadFeedbackData.count', 0] }, 0] + $ifNull: [{ $arrayElemAt: ['$chatItemsData.badFeedback', 0] }, 0] }, customFeedbacksCount: { - $ifNull: [{ $arrayElemAt: ['$customFeedbacksData.count', 0] }, 0] + $ifNull: [{ $arrayElemAt: ['$chatItemsData.customFeedback', 0] }, 0] }, - markCount: { $ifNull: [{ $arrayElemAt: ['$markData.count', 0] }, 0] }, - messageCount: { $ifNull: [{ $arrayElemAt: ['$messageCountData.messageCount', 0] }, 0] } + markCount: { $ifNull: [{ $arrayElemAt: ['$chatItemsData.adminMark', 0] }, 0] } } }, { diff --git a/projects/app/src/web/context/useInitApp.ts b/projects/app/src/web/context/useInitApp.ts index b06e13f30..6b5e4a478 100644 --- a/projects/app/src/web/context/useInitApp.ts +++ b/projects/app/src/web/context/useInitApp.ts @@ -43,6 +43,7 @@ export const useInitApp = () => { const router = useRouter(); const { hiId, bd_vid, k, sourceDomain, utm_source, utm_medium, utm_content, utm_workflow } = router.query as MarketingQueryParams; + const { loadGitStar, setInitd, feConfigs } = useSystemStore(); const { userInfo } = useUserStore(); const [scripts, setScripts] = useState([]);