mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 00:02:54 -04:00
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>
This commit is contained in:
parent
a0de24083e
commit
8b1fab4795
1 changed files with 16 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue