mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 07:31:19 +00:00

* feat: operation index * fix: delete update vector * perf: Clear invalid data * perf: index * perf: cleare invalid data * index
37 lines
997 B
TypeScript
37 lines
997 B
TypeScript
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
|
||
import { Schema, getMongoModel } from '../../mongo';
|
||
import { type MongoImageSchemaType } from '@fastgpt/global/common/file/image/type.d';
|
||
|
||
const ImageSchema = new Schema({
|
||
teamId: {
|
||
type: Schema.Types.ObjectId,
|
||
ref: TeamCollectionName,
|
||
required: true
|
||
},
|
||
createTime: {
|
||
type: Date,
|
||
default: () => new Date()
|
||
},
|
||
expiredTime: Date,
|
||
binary: Buffer,
|
||
metadata: Object
|
||
});
|
||
|
||
try {
|
||
// tts expired(60 Minutes)
|
||
ImageSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 60 * 60 });
|
||
ImageSchema.index({ type: 1 });
|
||
// delete related img
|
||
ImageSchema.index({ teamId: 1, 'metadata.relatedId': 1 });
|
||
|
||
// Cron clear invalid img
|
||
ImageSchema.index(
|
||
{ createTime: 1 },
|
||
{ partialFilterExpression: { 'metadata.relatedId': { $exists: true } } }
|
||
);
|
||
} catch (error) {
|
||
console.log(error);
|
||
}
|
||
|
||
export const MongoImage = getMongoModel<MongoImageSchemaType>('image', ImageSchema);
|