|
1 | 1 | import { connectionMongo, getMongoModel } from '../../common/mongo'; |
2 | 2 | const { Schema } = connectionMongo; |
3 | | -import { type ChatItemSchema as ChatItemType } from '@fastgpt/global/core/chat/type'; |
| 3 | +import { type ChatItemSchemaType } from '@fastgpt/global/core/chat/type'; |
4 | 4 | import { ChatRoleMap } from '@fastgpt/global/core/chat/constants'; |
5 | 5 | import { getNanoid } from '@fastgpt/global/common/string/tools'; |
6 | 6 | import { |
@@ -81,22 +81,29 @@ const ChatItemSchema = new Schema({ |
81 | 81 | } |
82 | 82 | }, |
83 | 83 | isFeedbackRead: Boolean, |
| 84 | + deleteTime: { |
| 85 | + type: Date, |
| 86 | + default: null |
| 87 | + }, |
84 | 88 |
|
85 | 89 | // @deprecated |
86 | 90 | [DispatchNodeResponseKeyEnum.nodeResponse]: Array |
87 | 91 | }); |
88 | 92 |
|
89 | | -/* |
90 | | - delete by app; |
| 93 | +/* |
| 94 | + delete by app; |
91 | 95 | delete by chat id; |
92 | | - get chat list; |
93 | | - get chat logs; |
94 | | - close custom feedback; |
| 96 | + close custom feedback; |
95 | 97 | */ |
96 | 98 | ChatItemSchema.index({ appId: 1, chatId: 1, dataId: 1 }); |
97 | | -// Anchor filter |
| 99 | +// Get histories |
| 100 | +ChatItemSchema.index({ appId: 1, chatId: 1, deleteTime: 1 }); |
| 101 | +// get chatitem list,Anchor filter |
98 | 102 | ChatItemSchema.index({ appId: 1, chatId: 1, _id: -1 }); |
99 | | -// timer, clear history |
100 | | -ChatItemSchema.index({ teamId: 1, time: -1 }); |
| 103 | +// Query by role (AI/Human), get latest chat item, permission check |
| 104 | +ChatItemSchema.index({ appId: 1, chatId: 1, obj: 1, _id: -1 }); |
101 | 105 |
|
102 | | -export const MongoChatItem = getMongoModel<ChatItemType>(ChatItemCollectionName, ChatItemSchema); |
| 106 | +export const MongoChatItem = getMongoModel<ChatItemSchemaType>( |
| 107 | + ChatItemCollectionName, |
| 108 | + ChatItemSchema |
| 109 | +); |
0 commit comments