aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2024-05-08 21:03:06 +0100
committernextcloud-command <nextcloud-command@users.noreply.github.com>2024-05-16 16:27:59 +0000
commitc6a0f23bb5793482d185b7b5687209f1b1b0d443 (patch)
tree0f1375d46b8419da5bbbff16098b5c24e016e6c0 /apps/files/src
parent10dfb76f283a360e704839e4eca647806db78411 (diff)
downloadnextcloud-server-c6a0f23bb5793482d185b7b5687209f1b1b0d443.tar.gz
nextcloud-server-c6a0f23bb5793482d185b7b5687209f1b1b0d443.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> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'apps/files/src')
-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 348bce6a255..8148dd59515 100644
--- a/apps/files/src/actions/deleteAction.ts
+++ b/apps/files/src/actions/deleteAction.ts
@@ -29,6 +29,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
@@ -58,6 +59,8 @@ const isAllFolders = (nodes: Node[]) => {
return !nodes.some(node => node.type !== FileType.Folder)
}
+const queue = new PQueue({ concurrency: 1 })
+
export const action = new FileAction({
id: 'delete',
displayName(nodes: Node[], view: View) {
@@ -152,7 +155,19 @@ export const action = new FileAction({
}
},
async execBatch(nodes: Node[], view: View, dir: string) {
- 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,