1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Cache flow library result to improve response time

Fixes #1753
This commit is contained in:
Nick O'Leary 2018-06-06 21:38:44 +01:00
parent 472bbdb59f
commit 3b0300b834
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -25,6 +25,8 @@ var storageModule;
var settingsAvailable; var settingsAvailable;
var sessionsAvailable; var sessionsAvailable;
var libraryFlowsCachedResult = null;
function moduleSelector(aSettings) { function moduleSelector(aSettings) {
var toReturn; var toReturn;
if (aSettings.storageModule) { if (aSettings.storageModule) {
@ -156,7 +158,14 @@ var storageModuleInterface = {
if (storageModule.hasOwnProperty("getAllFlows")) { if (storageModule.hasOwnProperty("getAllFlows")) {
return storageModule.getAllFlows(); return storageModule.getAllFlows();
} else { } else {
return listFlows("/"); if (libraryFlowsCachedResult) {
return Promise.resolve(libraryFlowsCachedResult);
} else {
return listFlows("/").then(function(result) {
libraryFlowsCachedResult = result;
return result;
});
}
} }
}, },
getFlow: function(fn) { getFlow: function(fn) {
@ -178,6 +187,7 @@ var storageModuleInterface = {
err.code = "forbidden"; err.code = "forbidden";
return when.reject(err); return when.reject(err);
} }
libraryFlowsCachedResult = null;
if (storageModule.hasOwnProperty("saveFlow")) { if (storageModule.hasOwnProperty("saveFlow")) {
return storageModule.saveFlow(fn, data); return storageModule.saveFlow(fn, data);
} else { } else {