mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 23:55:36 +00:00

* feat: operation index * fix: delete update vector * perf: Clear invalid data * perf: index * perf: cleare invalid data * index
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { Schema, getMongoLogModel } from '../../common/mongo';
|
|
import { type OperationLogSchema } from '@fastgpt/global/support/operationLog/type';
|
|
import { OperationLogEventEnum } from '@fastgpt/global/support/operationLog/constants';
|
|
import {
|
|
TeamCollectionName,
|
|
TeamMemberCollectionName
|
|
} from '@fastgpt/global/support/user/team/constant';
|
|
|
|
export const OperationLogCollectionName = 'operationLogs';
|
|
|
|
const OperationLogSchema = new Schema({
|
|
tmbId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: TeamMemberCollectionName,
|
|
required: true
|
|
},
|
|
teamId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: TeamCollectionName,
|
|
required: true
|
|
},
|
|
timestamp: {
|
|
type: Date,
|
|
default: () => new Date()
|
|
},
|
|
event: {
|
|
type: String,
|
|
enum: Object.values(OperationLogEventEnum),
|
|
required: true
|
|
},
|
|
metadata: {
|
|
type: Object,
|
|
default: {}
|
|
}
|
|
});
|
|
|
|
OperationLogSchema.index({ teamId: 1, tmbId: 1, event: 1 });
|
|
OperationLogSchema.index({ timestamp: 1 }, { expireAfterSeconds: 14 * 24 * 60 * 60 }); // Auto delete after 14 days
|
|
|
|
export const MongoOperationLog = getMongoLogModel<OperationLogSchema>(
|
|
OperationLogCollectionName,
|
|
OperationLogSchema
|
|
);
|