update parent

This commit is contained in:
archer 2025-12-24 13:35:54 +08:00
parent 7738b48fc9
commit ad19a5d083
No known key found for this signature in database
GPG Key ID: 4446499B846D4A9E
6 changed files with 33 additions and 42 deletions

View File

@ -27,8 +27,9 @@ import { getS3ChatSource } from '../../common/s3/sources/chat';
import { MongoAppChatLog } from './logs/chatLogsSchema';
import { MongoAppRegistration } from '../../support/appRegistration/schema';
import { MongoMcpKey } from '../../support/mcp/schema';
import { type ClientSession } from '../../common/mongo';
import { MongoAppRecord } from './record/schema';
import { mongoSessionRun } from '../../common/mongo/sessionRun';
import { addLog } from '../../common/system/log';
export const beforeUpdateAppFormat = ({ nodes }: { nodes?: StoreNodeItemType[] }) => {
if (!nodes) return;
@ -210,23 +211,21 @@ export const deleteAppsImmediate = async ({
await MongoAppRecord.deleteMany({ teamId, appId: { $in: appIds } });
};
export const updateParentFoldersUpdateTime = async ({
parentId,
session
}: {
parentId?: string | null;
session?: ClientSession;
}) => {
while (true) {
if (!parentId) return;
export const updateParentFoldersUpdateTime = ({ parentId }: { parentId?: string | null }) => {
mongoSessionRun(async (session) => {
while (true) {
if (!parentId) return;
const parentApp = await MongoApp.findById(parentId, 'parentId updateTime');
if (!parentApp) return;
const parentApp = await MongoApp.findById(parentId, 'parentId updateTime');
if (!parentApp) return;
parentApp.updateTime = new Date();
await parentApp.save({ session });
parentApp.updateTime = new Date();
await parentApp.save({ session });
// 递归更新上层
parentId = parentApp.parentId;
}
// 递归更新上层
parentId = parentApp.parentId;
}
}).catch((err) => {
addLog.error('updateParentFoldersUpdateTime error', err);
});
};

View File

@ -244,9 +244,8 @@ export const onCreateApp = async ({
await getS3AvatarSource().refreshAvatar(_avatar, undefined, session);
await updateParentFoldersUpdateTime({
parentId,
session
updateParentFoldersUpdateTime({
parentId
});
(async () => {

View File

@ -52,11 +52,6 @@ async function handler(req: ApiRequestProps<UpdateHttpPluginBody>, res: NextApiR
{ session }
);
await updateParentFoldersUpdateTime({
parentId: app.parentId,
session
});
await MongoAppVersion.updateOne(
{ appId },
{
@ -67,6 +62,9 @@ async function handler(req: ApiRequestProps<UpdateHttpPluginBody>, res: NextApiR
{ session }
);
});
updateParentFoldersUpdateTime({
parentId: app.parentId
});
}
export default NextAPI(handler);

View File

@ -53,11 +53,6 @@ async function handler(
{ session }
);
await updateParentFoldersUpdateTime({
parentId: app.parentId,
session
});
await MongoAppVersion.updateOne(
{ appId },
{
@ -68,6 +63,9 @@ async function handler(
{ session }
);
});
updateParentFoldersUpdateTime({
parentId: app.parentId
});
return {};
}

View File

@ -134,26 +134,24 @@ async function handler(req: ApiRequestProps<AppUpdateBody, AppUpdateQuery>) {
edges
}),
...(chatConfig && { chatConfig }),
...(isMove && { inheritPermission: true })
...(isMove && { inheritPermission: true }),
updateTime: new Date()
},
{ session }
);
if (isMove) {
// Update both old and new parent folders
await updateParentFoldersUpdateTime({
parentId: app.parentId,
session
updateParentFoldersUpdateTime({
parentId: app.parentId
});
await updateParentFoldersUpdateTime({
parentId,
session
updateParentFoldersUpdateTime({
parentId
});
} else {
// Update current parent folder
await updateParentFoldersUpdateTime({
parentId: parentId || app.parentId,
session
updateParentFoldersUpdateTime({
parentId: parentId || app.parentId
});
}

View File

@ -29,8 +29,7 @@ async function handler(req: ApiRequestProps<PostPublishAppProps>, res: NextApiRe
beforeUpdateAppFormat({
nodes
});
await updateParentFoldersUpdateTime({
updateParentFoldersUpdateTime({
parentId: app.parentId
});