perf: chat log list (#4704)

* perf: chat log list

* remove log
This commit is contained in:
Archer
2025-04-28 18:19:15 +08:00
committed by GitHub
parent e0b85ca4c2
commit d2a32c363d
4 changed files with 21 additions and 92 deletions

View File

@@ -14,6 +14,7 @@ weight: 792
## ⚙️ 优化
1. Chat log list 优化,避免大数据时超出内存限制。
## 🐛 修复

View File

@@ -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')
}

View File

@@ -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] }
}
},
{

View File

@@ -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<FastGPTFeConfigsType['scripts']>([]);