Skip to content

Commit

Permalink
fix: chat index
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jul 16, 2024
1 parent 259bc0d commit 915a1f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
11 changes: 6 additions & 5 deletions packages/service/common/mongo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export const getMongoModel = <T>(name: string, schema: mongoose.Schema) => {

const model = connectionMongo.model<T>(name, schema);

try {
// model.createIndexes({ background: true });
model.syncIndexes({ background: true });
} catch (error) {
addLog.error('Create index error', error);
if (process.env.SYNC_INDEX !== '0') {
try {
model.syncIndexes({ background: true });
} catch (error) {
addLog.error('Create index error', error);
}
}

return model;
Expand Down
5 changes: 1 addition & 4 deletions packages/service/core/chat/chatItemSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ try {
get chat logs;
close custom feedback;
*/
ChatItemSchema.index(
{ appId: 1, chatId: 1, dataId: 1 },
{ background: true, unique: true, name: 'appid_1_chatid_1_dataid_1_unique' }
);
ChatItemSchema.index({ appId: 1, chatId: 1, dataId: 1 }, { background: true });
// admin charts
ChatItemSchema.index({ time: -1, obj: 1 }, { background: true });
// timer, clear history
Expand Down
5 changes: 1 addition & 4 deletions packages/service/core/chat/chatSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ try {
// get user history
ChatSchema.index({ tmbId: 1, appId: 1, top: -1, updateTime: -1 }, { background: true });
// delete by appid; clear history; init chat; update chat; auth chat; get chat;
ChatSchema.index(
{ appId: 1, chatId: 1 },
{ background: true, unique: true, name: 'appid_1_chatid_1_unique' }
);
ChatSchema.index({ appId: 1, chatId: 1 }, { background: true });

// get chat logs;
ChatSchema.index({ teamId: 1, appId: 1, updateTime: -1 }, { background: true });
Expand Down

0 comments on commit 915a1f8

Please sign in to comment.