Skip to content

Commit

Permalink
Added a local cache for lock discovery in PROPFIND
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 7, 2017
1 parent 40fa39a commit bc744b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
18 changes: 15 additions & 3 deletions lib/server/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
Expand All @@ -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 {
Expand All @@ -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', {
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions src/server/commands/Propfind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>)
function lockDiscovery(lockDiscoveryCache : any, arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback<any>)
{
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)
{
Expand All @@ -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
Expand Down Expand Up @@ -47,6 +61,8 @@ export default function(arg : MethodCallArgs, callback)
return;
}

const lockDiscoveryCache = {};

arg.checkIfHeader(resource, () => {
const targetSource = arg.findHeader('source', 'F').toUpperCase() === 'T';

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc744b0

Please sign in to comment.