Skip to content

Commit 8b1fab4

Browse files
nfebebackportbot[bot]
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 a0de240 commit 8b1fab4

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

apps/files/src/actions/deleteAction.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import NetworkOffSvg from '@mdi/svg/svg/network-off.svg?raw'
3030
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'
3131

3232
import logger from '../logger.js'
33+
import PQueue from 'p-queue'
3334

3435
const canUnshareOnly = (nodes: Node[]) => {
3536
return nodes.every(node => node.attributes['is-mount-root'] === true
@@ -119,6 +120,8 @@ const displayName = (nodes: Node[], view: View) => {
119120
return t('files', 'Delete')
120121
}
121122

123+
const queue = new PQueue({ concurrency: 1 })
124+
122125
export const action = new FileAction({
123126
id: 'delete',
124127
displayName,
@@ -183,7 +186,19 @@ export const action = new FileAction({
183186
return Promise.all(nodes.map(() => false))
184187
}
185188

186-
return Promise.all(nodes.map(node => this.exec(node, view, dir)))
189+
// Map each node to a promise that resolves with the result of exec(node)
190+
const promises = nodes.map(node => {
191+
// Create a promise that resolves with the result of exec(node)
192+
const promise = new Promise<boolean>(resolve => {
193+
queue.add(async () => {
194+
const result = await this.exec(node, view, dir)
195+
resolve(result !== null ? result : false)
196+
})
197+
})
198+
return promise
199+
})
200+
201+
return Promise.all(promises)
187202
},
188203

189204
order: 100,

0 commit comments

Comments
 (0)