From bc744b0eab82c2534639e2843f2eaeea8109be31 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Wed, 7 Jun 2017 10:01:54 +0200 Subject: [PATCH] Added a local cache for lock discovery in PROPFIND --- lib/server/commands/Propfind.js | 18 +++++++++++++++--- src/server/commands/Propfind.ts | 22 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/server/commands/Propfind.js b/lib/server/commands/Propfind.js index 3fb6997f..237301f4 100644 --- a/lib/server/commands/Propfind.js +++ b/lib/server/commands/Propfind.js @@ -5,7 +5,18 @@ var IResource_1 = require("../../resource/IResource"); var FSPath_1 = require("../../manager/FSPath"); var XML_1 = require("../../helper/XML"); var http = require("http"); -function lockDiscovery(arg, path, resource, callback) { +function lockDiscovery(lockDiscoveryCache, arg, path, resource, callback) { + var cached = lockDiscoveryCache[path.toString()]; + if (cached) { + callback(null, cached); + return; + } + var _Callback = callback; + callback = function (e, l) { + if (!e) + lockDiscoveryCache[path.toString()] = l; + _Callback(e, l); + }; arg.requireErPrivilege('canListLocks', resource, function (e, can) { if (e || !can) { callback(e, {}); @@ -14,7 +25,7 @@ function lockDiscovery(arg, path, resource, callback) { resource.getLocks(function (e, locks) { if (resource.parent) { var parentPath = path.getParent(); - lockDiscovery(arg, parentPath, resource.parent, function (e, l) { + lockDiscovery(lockDiscoveryCache, arg, parentPath, resource.parent, function (e, l) { if (e) callback(e, null); else { @@ -38,6 +49,7 @@ function default_1(arg, callback) { callback(); return; } + var lockDiscoveryCache = {}; arg.checkIfHeader(resource, function () { var targetSource = arg.findHeader('source', 'F').toUpperCase() === 'T'; var multistatus = XML_1.XML.createElement('D:multistatus', { @@ -110,7 +122,7 @@ function default_1(arg, callback) { if (!e) { response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20')); var lockdiscovery_1 = prop.ele('D:lockdiscovery'); - lockDiscovery(arg, new FSPath_1.FSPath(path), resource, function (e, l) { + lockDiscovery(lockDiscoveryCache, arg, new FSPath_1.FSPath(path), resource, function (e, l) { if (e) { nbOut(e); return; diff --git a/src/server/commands/Propfind.ts b/src/server/commands/Propfind.ts index 884db364..eee6b7b1 100644 --- a/src/server/commands/Propfind.ts +++ b/src/server/commands/Propfind.ts @@ -6,8 +6,22 @@ import { Lock } from '../../resource/lock/Lock' import { XML } from '../../helper/XML' import * as http from 'http' -function lockDiscovery(arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback) +function lockDiscovery(lockDiscoveryCache : any, arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback) { + const cached = lockDiscoveryCache[path.toString()]; + if(cached) + { + callback(null, cached); + return; + } + + const _Callback = callback; + callback = (e, l) => { + if(!e) + lockDiscoveryCache[path.toString()] = l; + _Callback(e, l); + } + arg.requireErPrivilege('canListLocks', resource, (e, can) => { if(e || !can) { @@ -19,7 +33,7 @@ function lockDiscovery(arg : MethodCallArgs, path : FSPath, resource : IResource if(resource.parent) { const parentPath = path.getParent(); - lockDiscovery(arg, parentPath, resource.parent, (e, l) => { + lockDiscovery(lockDiscoveryCache, arg, parentPath, resource.parent, (e, l) => { if(e) callback(e, null); else @@ -47,6 +61,8 @@ export default function(arg : MethodCallArgs, callback) return; } + const lockDiscoveryCache = {}; + arg.checkIfHeader(resource, () => { const targetSource = arg.findHeader('source', 'F').toUpperCase() === 'T'; @@ -144,7 +160,7 @@ export default function(arg : MethodCallArgs, callback) { response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20')); const lockdiscovery = prop.ele('D:lockdiscovery'); - lockDiscovery(arg, new FSPath(path), resource, (e, l) => { + lockDiscovery(lockDiscoveryCache, arg, new FSPath(path), resource, (e, l) => { if(e) { nbOut(e);