Skip to content

Commit d55fdfd

Browse files
nfebeartonge
authored andcommitted
perf(deleteAction): Queue delete requests
When multiple files are deleted at once, all the requests bombard the server simultaneously, causing performance issues. This commit adds queuing that limits the concurrency of these requests to 5 at a time. Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
1 parent 031810d commit d55fdfd

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

apps/files/src/actions/deleteAction.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const isAllFolders = (nodes: Node[]) => {
5959
return !nodes.some(node => node.type !== FileType.Folder)
6060
}
6161

62+
const queue = new PQueue({ concurrency: 1 })
63+
6264
export const action = new FileAction({
6365
id: 'delete',
6466
displayName(nodes: Node[], view: View) {
@@ -153,7 +155,19 @@ export const action = new FileAction({
153155
}
154156
},
155157
async execBatch(nodes: Node[], view: View, dir: string) {
156-
return Promise.all(nodes.map(node => this.exec(node, view, dir)))
158+
// Map each node to a promise that resolves with the result of exec(node)
159+
const promises = nodes.map(node => {
160+
// Create a promise that resolves with the result of exec(node)
161+
const promise = new Promise<boolean>(resolve => {
162+
queue.add(async () => {
163+
const result = await this.exec(node, view, dir)
164+
resolve(result !== null ? result : false)
165+
})
166+
})
167+
return promise
168+
})
169+
170+
return Promise.all(promises)
157171
},
158172

159173
order: 100,

0 commit comments

Comments
 (0)