mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-02 01:02:05 +08:00
perf: chat pane (#5462)
* fix: sync pane with URL appId vs Home appId to avoid cross-tab interference (#5456) * perf: chat pane * perf: markdown render * update app chat logs index * doc * doc redirect --------- Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com>
This commit is contained in:
@@ -5,15 +5,15 @@ import { AppCollectionName } from '../schema';
|
||||
export const ChatLogCollectionName = 'app_chat_logs';
|
||||
|
||||
const ChatLogSchema = new Schema({
|
||||
teamId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
required: true
|
||||
},
|
||||
appId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: AppCollectionName,
|
||||
required: true
|
||||
},
|
||||
teamId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
required: true
|
||||
},
|
||||
chatId: {
|
||||
type: String,
|
||||
required: true
|
||||
@@ -68,8 +68,15 @@ const ChatLogSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
// Get chart data
|
||||
ChatLogSchema.index({ teamId: 1, appId: 1, source: 1, updateTime: -1 });
|
||||
ChatLogSchema.index({ userId: 1, appId: 1, source: 1, createTime: -1 });
|
||||
// Get chart data isFirstChat
|
||||
ChatLogSchema.index({ isFirstChat: 1, teamId: 1, appId: 1, source: 1, createTime: -1 });
|
||||
// Get userStats
|
||||
ChatLogSchema.index({ teamId: 1, appId: 1, userId: 1 });
|
||||
|
||||
// Init shell
|
||||
ChatLogSchema.index({ teamId: 1, appId: 1, chatId: 1 });
|
||||
|
||||
export const MongoAppChatLog = getMongoLogModel<AppChatLogSchema>(
|
||||
ChatLogCollectionName,
|
||||
|
||||
@@ -90,7 +90,7 @@ const ChatSchema = new Schema({
|
||||
|
||||
try {
|
||||
// Tmp
|
||||
ChatSchema.index({ initStatistics: 1 });
|
||||
ChatSchema.index({ initStatistics: 1, _id: -1 });
|
||||
ChatSchema.index({ appId: 1, tmbId: 1, outLinkUid: 1 });
|
||||
|
||||
ChatSchema.index({ chatId: 1 });
|
||||
@@ -100,7 +100,7 @@ try {
|
||||
ChatSchema.index({ appId: 1, chatId: 1 });
|
||||
|
||||
// get chat logs;
|
||||
ChatSchema.index({ teamId: 1, appId: 1, updateTime: -1, sources: 1 });
|
||||
ChatSchema.index({ teamId: 1, appId: 1, sources: 1, tmbId: 1, updateTime: -1 });
|
||||
// get share chat history
|
||||
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 });
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ export async function saveChat({
|
||||
) || 0;
|
||||
|
||||
const hasHistoryChat = await MongoAppChatLog.exists({
|
||||
teamId,
|
||||
appId,
|
||||
userId,
|
||||
createTime: { $lt: now }
|
||||
@@ -185,8 +186,9 @@ export async function saveChat({
|
||||
|
||||
await MongoAppChatLog.updateOne(
|
||||
{
|
||||
chatId,
|
||||
teamId,
|
||||
appId,
|
||||
chatId,
|
||||
updateTime: { $gte: fifteenMinutesAgo }
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ const UsageSchema = new Schema({
|
||||
});
|
||||
|
||||
try {
|
||||
UsageSchema.index({ teamId: 1, tmbId: 1, source: 1, time: 1, appName: 1 });
|
||||
UsageSchema.index({ teamId: 1, tmbId: 1, source: 1, time: 1, appName: 1, _id: -1 });
|
||||
// timer task. clear dead team
|
||||
// UsageSchema.index({ teamId: 1, time: -1 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user