perf: completion chatId

This commit is contained in:
archer
2023-07-23 20:07:35 +08:00
parent b7d18e38d1
commit 67e10d6f2c
35 changed files with 447 additions and 385 deletions

View File

@@ -17,14 +17,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
userId,
...(appId && { appId })
},
'_id title top customTitle appId updateTime'
'chatId title top customTitle appId updateTime'
)
.sort({ top: -1, updateTime: -1 })
.limit(20);
jsonRes<ChatHistoryItemType[]>(res, {
data: data.map((item) => ({
_id: item._id,
chatId: item.chatId,
updateTime: item.updateTime,
appId: item.appId,
customTitle: item.customTitle,

View File

@@ -3,7 +3,6 @@ import { jsonRes } from '@/service/response';
import { connectToDatabase, Chat } from '@/service/mongo';
import { authUser } from '@/service/utils/auth';
import { Types } from 'mongoose';
import { rawSearchKey } from '@/constants/chat';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
@@ -36,13 +35,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
{
$project: {
[rawSearchKey]: `$content.${rawSearchKey}`
// [rawSearchKey]: `$content.${rawSearchKey}`
}
}
]);
jsonRes(res, {
data: history[0]?.[rawSearchKey] || []
// data: history[0]?.[rawSearchKey] || []
});
} catch (err) {
jsonRes(res, {

View File

@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await Chat.findOneAndUpdate(
{
_id: chatId,
chatId,
userId
},
{

View File

@@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await Chat.updateOne(
{
_id: new Types.ObjectId(chatId),
chatId,
userId: new Types.ObjectId(userId),
'content._id': new Types.ObjectId(contentId)
},