From 5631ec781e408c90fa66abf12f76b189b9b8d5a8 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Fri, 19 Dec 2025 12:13:44 +0800 Subject: [PATCH] rename log (#6124) * rename log * mq del log --- packages/global/support/user/audit/type.d.ts | 4 ++-- packages/service/common/s3/mq.ts | 11 ++++++++++- packages/service/core/chat/chatSchema.ts | 8 ++++---- packages/service/support/user/audit/schema.ts | 15 ++++++++------- packages/service/support/user/audit/util.ts | 4 ++-- packages/service/support/wallet/sub/schema.ts | 14 ++++---------- .../web/support/user/team/operantionLog/api.ts | 4 ++-- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/packages/global/support/user/audit/type.d.ts b/packages/global/support/user/audit/type.d.ts index 099745c61..610039fd3 100644 --- a/packages/global/support/user/audit/type.d.ts +++ b/packages/global/support/user/audit/type.d.ts @@ -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; }; -export type OperationListItemType = { +export type TeamAuditListItemType = { _id: string; sourceMember: SourceMemberType; event: `${AuditEventEnum}`; diff --git a/packages/service/common/s3/mq.ts b/packages/service/common/s3/mq.ts index a85d936ad..6ab32b984 100644 --- a/packages/service/common/s3/mq.ts +++ b/packages/service/common/s3/mq.ts @@ -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[] = []; 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[] = []; return new Promise(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); }); }); diff --git a/packages/service/core/chat/chatSchema.ts b/packages/service/core/chat/chatSchema.ts index 1979d3575..6bb62cc74 100644 --- a/packages/service/core/chat/chatSchema.ts +++ b/packages/service/core/chat/chatSchema.ts @@ -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); } diff --git a/packages/service/support/user/audit/schema.ts b/packages/service/support/user/audit/schema.ts index ff2247208..e0b9f690d 100644 --- a/packages/service/support/user/audit/schema.ts +++ b/packages/service/support/user/audit/schema.ts @@ -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( - OperationLogCollectionName, - OperationLogSchema +export const MongoTeamAudit = getMongoLogModel( + TeamAuditCollectionName, + TeamAuditSchema ); diff --git a/packages/service/support/user/audit/util.ts b/packages/service/support/user/audit/util.ts index 53be0c1a0..e8976b426 100644 --- a/packages/service/support/user/audit/util.ts +++ b/packages/service/support/user/audit/util.ts @@ -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({ params?: any; }) { retryFn(() => - MongoOperationLog.create({ + MongoTeamAudit.create({ tmbId: tmbId, teamId: teamId, event, diff --git a/packages/service/support/wallet/sub/schema.ts b/packages/service/support/wallet/sub/schema.ts index d0a435aa2..93532bd7d 100644 --- a/packages/service/support/wallet/sub/schema.ts +++ b/packages/service/support/wallet/sub/schema.ts @@ -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 { diff --git a/projects/app/src/web/support/user/team/operantionLog/api.ts b/projects/app/src/web/support/user/team/operantionLog/api.ts index af359543a..22b73fa73 100644 --- a/projects/app/src/web/support/user/team/operantionLog/api.ts +++ b/projects/app/src/web/support/user/team/operantionLog/api.ts @@ -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>(`/proApi/support/user/audit/list`, props); +) => POST>(`/proApi/support/user/audit/list`, props);