From d92538850f9d031d7e1d80479e259050f86d73ae Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Wed, 1 Feb 2023 08:17:26 +0100 Subject: fix: Limit trashbin restore/delete to 2 concurrent request to avoid locking in the backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_trashbin/src/filelist.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'apps') diff --git a/apps/files_trashbin/src/filelist.js b/apps/files_trashbin/src/filelist.js index 8920dcbf8b9..e113b0f0ffa 100644 --- a/apps/files_trashbin/src/filelist.js +++ b/apps/files_trashbin/src/filelist.js @@ -25,6 +25,9 @@ * */ +// eslint-disable-next-line import/no-unresolved, node/no-missing-import +import PQueue from 'p-queue' + /* eslint-disable */ (function() { var DELETED_REGEXP = new RegExp(/^(.+)\.d[0-9]+$/) @@ -61,6 +64,7 @@ var FileList = function($el, options) { this.client = options.client this.initialize($el, options) + this.deleteOperationQueue = new PQueue({ concurrency: 4 }) } FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, /** @lends OCA.Trashbin.FileList.prototype */ { @@ -185,12 +189,10 @@ this.fileMultiSelectMenu.toggleLoading('restore', true) var restorePromises = files.map(function(file) { - return self.client.move(OC.joinPaths('trash', self.getCurrentDirectory(), file), OC.joinPaths('restore', file), true) - .then( - function() { - self._removeCallback([file]) - } - ) + return self.deleteOperationQueue.add(async () => { + self.client.move(OC.joinPaths('trash', self.getCurrentDirectory(), file), OC.joinPaths('restore', file), true) + self._removeCallback([file]) + }) }) return Promise.all(restorePromises).then( function() { @@ -226,12 +228,10 @@ } else { this.fileMultiSelectMenu.toggleLoading('delete', true) var deletePromises = files.map(function(file) { - return self.client.remove(OC.joinPaths('trash', self.getCurrentDirectory(), file)) - .then( - function() { - self._removeCallback([file]) - } - ) + return self.deleteOperationQueue.add(async () => { + await self.client.remove(OC.joinPaths('trash', self.getCurrentDirectory(), file)) + self._removeCallback([file]) + }) }) return Promise.all(deletePromises).then( function() { -- cgit v1.2.3