rename log (#6124)

* rename log

* mq del log
This commit is contained in:
Archer 2025-12-19 12:13:44 +08:00 committed by GitHub
parent d398c9cd39
commit 5631ec781e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 32 additions and 28 deletions

View File

@ -1,7 +1,7 @@
import type { SourceMemberType } from '../user/type';
import type { AuditEventEnum } from './constants';
export type OperationLogSchema = {
export type TeamAuditSchemaType = {
_id: string;
tmbId: string;
teamId: string;
@ -10,7 +10,7 @@ export type OperationLogSchema = {
metadata?: Record<string, string>;
};
export type OperationListItemType = {
export type TeamAuditListItemType = {
_id: string;
sourceMember: SourceMemberType;
event: `${AuditEventEnum}`;

View File

@ -1,6 +1,7 @@
import { getQueue, getWorker, QueueNames } from '../bullmq';
import pLimit from 'p-limit';
import { retryFn } from '@fastgpt/global/common/system/utils';
import { addLog } from '../system/log';
export type S3MQJobData = {
key?: string;
@ -38,17 +39,22 @@ export const startS3DelWorker = async () => {
}
if (key) {
addLog.info(`[S3 delete] delete key: ${key}`);
await bucket.delete(key);
addLog.info(`[S3 delete] delete key: ${key} success`);
}
if (keys) {
addLog.info(`[S3 delete] delete keys: ${keys.length}`);
const tasks: Promise<void>[] = [];
for (const key of keys) {
const p = limit(() => retryFn(() => bucket.delete(key)));
tasks.push(p);
}
await Promise.all(tasks);
addLog.info(`[S3 delete] delete keys: ${keys.length} success`);
}
if (prefix) {
addLog.info(`[S3 delete] delete prefix: ${prefix}`);
const tasks: Promise<void>[] = [];
return new Promise<void>(async (resolve, reject) => {
const stream = bucket.listObjectsV2(prefix, true);
@ -67,16 +73,19 @@ export const startS3DelWorker = async () => {
const results = await Promise.allSettled(tasks);
const failed = results.filter((r) => r.status === 'rejected');
if (failed.length > 0) {
addLog.error(`[S3 delete] delete prefix: ${prefix} failed`);
reject('Some deletes failed');
}
addLog.info(`[S3 delete] delete prefix: ${prefix} success`);
resolve();
} catch (err) {
addLog.error(`[S3 delete] delete prefix: ${prefix} error`, err);
reject(err);
}
});
stream.on('error', (err) => {
console.error('listObjects stream error', err);
addLog.error(`[S3 delete] delete prefix: ${prefix} error`, err);
reject(err);
});
});

View File

@ -110,6 +110,9 @@ try {
ChatSchema.index({ chatId: 1 });
// get user history
ChatSchema.index({ tmbId: 1, appId: 1, deleteTime: 1, top: -1, updateTime: -1 });
// get share chat history
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 });
// delete by appid; clear history; init chat; update chat; auth chat; get chat;
ChatSchema.index({ appId: 1, chatId: 1 });
@ -191,11 +194,8 @@ try {
}
);
// get share chat history
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 });
// timer, clear history
ChatSchema.index({ teamId: 1, updateTime: -1 });
ChatSchema.index({ updateTime: -1, teamId: 1 });
} catch (error) {
console.log(error);
}

View File

@ -1,14 +1,14 @@
import { Schema, getMongoLogModel } from '../../../common/mongo';
import { type OperationLogSchema } from '@fastgpt/global/support/user/audit/type';
import { type TeamAuditSchemaType } from '@fastgpt/global/support/user/audit/type';
import { AdminAuditEventEnum, AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
import {
TeamCollectionName,
TeamMemberCollectionName
} from '@fastgpt/global/support/user/team/constant';
export const OperationLogCollectionName = 'operationLogs';
export const TeamAuditCollectionName = 'operationLogs';
const OperationLogSchema = new Schema({
const TeamAuditSchema = new Schema({
tmbId: {
type: Schema.Types.ObjectId,
ref: TeamMemberCollectionName,
@ -34,9 +34,10 @@ const OperationLogSchema = new Schema({
}
});
OperationLogSchema.index({ teamId: 1, tmbId: 1, event: 1 });
TeamAuditSchema.index({ teamId: 1, tmbId: 1, event: 1 });
TeamAuditSchema.index({ timestamp: 1, teamId: 1 });
export const MongoOperationLog = getMongoLogModel<OperationLogSchema>(
OperationLogCollectionName,
OperationLogSchema
export const MongoTeamAudit = getMongoLogModel<TeamAuditSchemaType>(
TeamAuditCollectionName,
TeamAuditSchema
);

View File

@ -1,7 +1,7 @@
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
import { i18nT } from '../../../../web/i18n/utils';
import { MongoOperationLog } from './schema';
import { MongoTeamAudit } from './schema';
import type {
AdminAuditEventEnum,
AuditEventEnum,
@ -86,7 +86,7 @@ export function addAuditLog<T extends AuditEventEnum | AdminAuditEventEnum>({
params?: any;
}) {
retryFn(() =>
MongoOperationLog.create({
MongoTeamAudit.create({
tmbId: tmbId,
teamId: teamId,
event,

View File

@ -67,18 +67,12 @@ const SubSchema = new Schema({
customDomain: Number,
// stand sub and extra points sub. Plan total points
totalPoints: {
type: Number
},
surplusPoints: {
// plan surplus points
type: Number
},
totalPoints: Number,
// plan surplus points
surplusPoints: Number,
// extra dataset size
currentExtraDatasetSize: {
type: Number
}
currentExtraDatasetSize: Number
});
try {

View File

@ -1,6 +1,6 @@
import { GET, POST, PUT } from '@/web/common/api/request';
import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
import type { OperationListItemType } from '@fastgpt/global/support/user/audit/type';
import type { TeamAuditListItemType } from '@fastgpt/global/support/user/audit/type';
import type { AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
export const getOperationLogs = (
@ -8,4 +8,4 @@ export const getOperationLogs = (
tmbIds?: string[];
events?: AuditEventEnum[];
}
) => POST<PaginationResponse<OperationListItemType>>(`/proApi/support/user/audit/list`, props);
) => POST<PaginationResponse<TeamAuditListItemType>>(`/proApi/support/user/audit/list`, props);