aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorTomasz Grobelny <tomasz@grobelny.net>2018-10-29 21:58:43 +0100
committerTomasz Grobelny <tomasz@grobelny.net>2018-10-30 15:37:21 +0100
commit68a27debd1e64f2dc21288fc5d43181bb61cd8f1 (patch)
treee1d3ca5233989a58665b4d43fbc079fd701cb3d2 /apps/files
parent963d968f062810e846f000f02f1be3f560c286f9 (diff)
downloadnextcloud-server-68a27debd1e64f2dc21288fc5d43181bb61cd8f1.tar.gz
nextcloud-server-68a27debd1e64f2dc21288fc5d43181bb61cd8f1.zip
Fix file move operation for large number of files
Signed-off-by: Tomasz Grobelny <tomasz@grobelny.net>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/js/filelist.js45
1 files changed, 40 insertions, 5 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 9cc1856d52b..31d80bbb246 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -2162,7 +2162,31 @@
if (!_.isArray(fileNames)) {
fileNames = [fileNames];
}
- _.each(fileNames, function(fileName) {
+
+ function Semaphore(max) {
+ var counter = 0;
+ var waiting = [];
+
+ this.acquire = function() {
+ if(counter < max) {
+ counter++;
+ return new Promise(function(resolve) { resolve(); });
+ } else {
+ return new Promise(function(resolve) { waiting.push(resolve); });
+ }
+ };
+
+ this.release = function() {
+ counter--;
+ if (waiting.length > 0 && counter < max) {
+ counter++;
+ var promise = waiting.shift();
+ promise();
+ }
+ };
+ }
+
+ var moveFileFunction = function(fileName) {
var $tr = self.findFileEl(fileName);
self.showFileBusyState($tr, true);
if (targetPath.charAt(targetPath.length - 1) !== '/') {
@@ -2170,7 +2194,7 @@
// not overwrite it
targetPath = targetPath + '/';
}
- self.filesClient.move(dir + fileName, targetPath + fileName)
+ return self.filesClient.move(dir + fileName, targetPath + fileName)
.done(function() {
// if still viewing the same directory
if (OC.joinPaths(self.getCurrentDirectory(), '/') === dir) {
@@ -2201,11 +2225,22 @@
.always(function() {
self.showFileBusyState($tr, false);
});
- if (callback) {
- callback();
- }
+ };
+
+ var mcSemaphore = new Semaphore(10);
+ var counter = 0;
+ _.each(fileNames, function(arg) {
+ mcSemaphore.acquire().then(function(){
+ moveFileFunction(arg).then(function(){
+ mcSemaphore.release();
+ counter++;
+ });
+ });
});
+ if (callback) {
+ callback();
+ }
},
/**