Skip to content

Commit 58711fb

Browse files
authored
Merge pull request #45327 from nextcloud/backport/45237/stable28
[stable28] perf(deleteAction): Queue delete requests
2 parents 4722123 + c6a0f23 commit 58711fb

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

apps/files/src/actions/deleteAction.ts

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

3131
import logger from '../logger.js'
32+
import PQueue from 'p-queue'
3233

3334
const canUnshareOnly = (nodes: Node[]) => {
3435
return nodes.every(node => node.attributes['is-mount-root'] === true
@@ -58,6 +59,8 @@ const isAllFolders = (nodes: Node[]) => {
5859
return !nodes.some(node => node.type !== FileType.Folder)
5960
}
6061

62+
const queue = new PQueue({ concurrency: 1 })
63+
6164
export const action = new FileAction({
6265
id: 'delete',
6366
displayName(nodes: Node[], view: View) {
@@ -152,7 +155,19 @@ export const action = new FileAction({
152155
}
153156
},
154157
async execBatch(nodes: Node[], view: View, dir: string) {
155-
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)
156171
},
157172

158173
order: 100,

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)