mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
update parent
This commit is contained in:
parent
7738b48fc9
commit
ad19a5d083
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -244,9 +244,8 @@ export const onCreateApp = async ({
|
|||
|
||||
await getS3AvatarSource().refreshAvatar(_avatar, undefined, session);
|
||||
|
||||
await updateParentFoldersUpdateTime({
|
||||
parentId,
|
||||
session
|
||||
updateParentFoldersUpdateTime({
|
||||
parentId
|
||||
});
|
||||
|
||||
(async () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ async function handler(req: ApiRequestProps<PostPublishAppProps>, res: NextApiRe
|
|||
beforeUpdateAppFormat({
|
||||
nodes
|
||||
});
|
||||
|
||||
await updateParentFoldersUpdateTime({
|
||||
updateParentFoldersUpdateTime({
|
||||
parentId: app.parentId
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue