Skip to content

Commit bc744b0

Browse files
committed
Added a local cache for lock discovery in PROPFIND
1 parent 40fa39a commit bc744b0

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lib/server/commands/Propfind.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ var IResource_1 = require("../../resource/IResource");
55
var FSPath_1 = require("../../manager/FSPath");
66
var XML_1 = require("../../helper/XML");
77
var http = require("http");
8-
function lockDiscovery(arg, path, resource, callback) {
8+
function lockDiscovery(lockDiscoveryCache, arg, path, resource, callback) {
9+
var cached = lockDiscoveryCache[path.toString()];
10+
if (cached) {
11+
callback(null, cached);
12+
return;
13+
}
14+
var _Callback = callback;
15+
callback = function (e, l) {
16+
if (!e)
17+
lockDiscoveryCache[path.toString()] = l;
18+
_Callback(e, l);
19+
};
920
arg.requireErPrivilege('canListLocks', resource, function (e, can) {
1021
if (e || !can) {
1122
callback(e, {});
@@ -14,7 +25,7 @@ function lockDiscovery(arg, path, resource, callback) {
1425
resource.getLocks(function (e, locks) {
1526
if (resource.parent) {
1627
var parentPath = path.getParent();
17-
lockDiscovery(arg, parentPath, resource.parent, function (e, l) {
28+
lockDiscovery(lockDiscoveryCache, arg, parentPath, resource.parent, function (e, l) {
1829
if (e)
1930
callback(e, null);
2031
else {
@@ -38,6 +49,7 @@ function default_1(arg, callback) {
3849
callback();
3950
return;
4051
}
52+
var lockDiscoveryCache = {};
4153
arg.checkIfHeader(resource, function () {
4254
var targetSource = arg.findHeader('source', 'F').toUpperCase() === 'T';
4355
var multistatus = XML_1.XML.createElement('D:multistatus', {
@@ -110,7 +122,7 @@ function default_1(arg, callback) {
110122
if (!e) {
111123
response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20'));
112124
var lockdiscovery_1 = prop.ele('D:lockdiscovery');
113-
lockDiscovery(arg, new FSPath_1.FSPath(path), resource, function (e, l) {
125+
lockDiscovery(lockDiscoveryCache, arg, new FSPath_1.FSPath(path), resource, function (e, l) {
114126
if (e) {
115127
nbOut(e);
116128
return;

src/server/commands/Propfind.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@ import { Lock } from '../../resource/lock/Lock'
66
import { XML } from '../../helper/XML'
77
import * as http from 'http'
88

9-
function lockDiscovery(arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback<any>)
9+
function lockDiscovery(lockDiscoveryCache : any, arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback<any>)
1010
{
11+
const cached = lockDiscoveryCache[path.toString()];
12+
if(cached)
13+
{
14+
callback(null, cached);
15+
return;
16+
}
17+
18+
const _Callback = callback;
19+
callback = (e, l) => {
20+
if(!e)
21+
lockDiscoveryCache[path.toString()] = l;
22+
_Callback(e, l);
23+
}
24+
1125
arg.requireErPrivilege('canListLocks', resource, (e, can) => {
1226
if(e || !can)
1327
{
@@ -19,7 +33,7 @@ function lockDiscovery(arg : MethodCallArgs, path : FSPath, resource : IResource
1933
if(resource.parent)
2034
{
2135
const parentPath = path.getParent();
22-
lockDiscovery(arg, parentPath, resource.parent, (e, l) => {
36+
lockDiscovery(lockDiscoveryCache, arg, parentPath, resource.parent, (e, l) => {
2337
if(e)
2438
callback(e, null);
2539
else
@@ -47,6 +61,8 @@ export default function(arg : MethodCallArgs, callback)
4761
return;
4862
}
4963

64+
const lockDiscoveryCache = {};
65+
5066
arg.checkIfHeader(resource, () => {
5167
const targetSource = arg.findHeader('source', 'F').toUpperCase() === 'T';
5268

@@ -144,7 +160,7 @@ export default function(arg : MethodCallArgs, callback)
144160
{
145161
response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20'));
146162
const lockdiscovery = prop.ele('D:lockdiscovery');
147-
lockDiscovery(arg, new FSPath(path), resource, (e, l) => {
163+
lockDiscovery(lockDiscoveryCache, arg, new FSPath(path), resource, (e, l) => {
148164
if(e)
149165
{
150166
nbOut(e);

0 commit comments

Comments
 (0)