perf: index

This commit is contained in:
archer
2023-06-25 15:52:04 +08:00
parent 68eca25df4
commit f56a339ad1
6 changed files with 18 additions and 9 deletions

View File

@@ -15,6 +15,10 @@ const TrainingDataSchema = new Schema({
ref: 'kb',
required: true
},
expireAt: {
type: Date,
default: () => new Date()
},
lockTime: {
type: Date,
default: () => new Date('2000/1/1')
@@ -44,5 +48,13 @@ const TrainingDataSchema = new Schema({
}
});
try {
TrainingDataSchema.index({ lockTime: 1 });
TrainingDataSchema.index({ userId: 1 });
TrainingDataSchema.index({ expireAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 });
} catch (error) {
console.log(error);
}
export const TrainingData: MongoModel<TrainingDateType> =
models['trainingData'] || model('trainingData', TrainingDataSchema);