summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2024-05-08 21:03:06 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-05-15 12:12:19 +0000
commit8b1fab4795c9f2744a65178f5bb32348198a116f (patch)
tree914de3c63992990fc5c75b73b250467c35be0f7b
parenta0de24083ef5159888e8fd5afb77f3b9621e4f02 (diff)
downloadnextcloud-server-8b1fab4795c9f2744a65178f5bb32348198a116f.tar.gz
nextcloud-server-8b1fab4795c9f2744a65178f5bb32348198a116f.zip
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>
-rw-r--r--apps/files/src/actions/deleteAction.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/apps/files/src/actions/deleteAction.ts b/apps/files/src/actions/deleteAction.ts
index 129ef0f9877..458cfd05eef 100644
--- a/apps/files/src/actions/deleteAction.ts
+++ b/apps/files/src/actions/deleteAction.ts
@@ -30,6 +30,7 @@ import NetworkOffSvg from '@mdi/svg/svg/network-off.svg?raw'
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'
import logger from '../logger.js'
+import PQueue from 'p-queue'
const canUnshareOnly = (nodes: Node[]) => {
return nodes.every(node => node.attributes['is-mount-root'] === true
@@ -119,6 +120,8 @@ const displayName = (nodes: Node[], view: View) => {
return t('files', 'Delete')
}
+const queue = new PQueue({ concurrency: 1 })
+
export const action = new FileAction({
id: 'delete',
displayName,
@@ -183,7 +186,19 @@ export const action = new FileAction({
return Promise.all(nodes.map(() => false))
}
- return Promise.all(nodes.map(node => this.exec(node, view, dir)))
+ // Map each node to a promise that resolves with the result of exec(node)
+ const promises = nodes.map(node => {
+ // Create a promise that resolves with the result of exec(node)
+ const promise = new Promise<boolean>(resolve => {
+ queue.add(async () => {
+ const result = await this.exec(node, view, dir)
+ resolve(result !== null ? result : false)
+ })
+ })
+ return promise
+ })
+
+ return Promise.all(promises)
},
order: 100,