From 36ec764095a0dee7e60788293b2ca15ab4e8463b Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Wed, 8 May 2024 21:03:06 +0100 Subject: [PATCH] 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 --- apps/files/src/actions/deleteAction.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files/src/actions/deleteAction.ts b/apps/files/src/actions/deleteAction.ts index 129ef0f987782..6c9129455c8e3 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: 5 }) + export const action = new FileAction({ id: 'delete', displayName, @@ -183,7 +186,7 @@ export const action = new FileAction({ return Promise.all(nodes.map(() => false)) } - return Promise.all(nodes.map(node => this.exec(node, view, dir))) + return Promise.all(nodes.map(node => queue.add(() => this.exec(node, view, dir)))) }, order: 100,