Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Assets): infinite loop on file delete #383

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions server/api/projectfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,23 @@ async function removeProjectFilesInternal(projectID: string, fileIDs: string[])
throw new Error("Missing Cloudflare credentials");
}

const parentFiles = await ProjectFile.find({
projectID,
fileID: { $in: fileIDs },
}).lean() as ProjectFileInterface[];

async function resolveAllChildren(searchFileIDs: string[]): Promise<ProjectFileInterface[]> {
const files = (await ProjectFile.find({
fileID: {
$in: searchFileIDs
},
const files = await ProjectFile.find({
projectID,
}).lean()) as ProjectFileInterface[];
parent: { $in: searchFileIDs },
}).lean() as ProjectFileInterface[];
if (!files?.length) return [];

const children = await resolveAllChildren(files.map((f) => f.fileID));
const children = await resolveAllChildren(files.map((o) => o.fileID).filter((o) => o));
return files.concat(children);
}

const objsToDelete = await resolveAllChildren(fileIDs);
const objsToDelete = (await resolveAllChildren(fileIDs)).concat(parentFiles);
const allFileIds = objsToDelete.map((o => o.fileID));

const filesToDelete = objsToDelete
Expand Down
Loading