From 019f077ea41eaa1c985c022f9731187b4179f51d Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Mon, 27 Jul 2015 11:46:27 +0530 Subject: [PATCH] fixing jaggery app performance issue --- .../jaggeryapps/iotserver/lib/fuse-router.js | 18 ++++---- .../jaggeryapps/iotserver/lib/fuse.jag | 26 +++++------ .../jaggeryapps/iotserver/lib/fuse.js | 46 +++++++++---------- .../iotserver/lib/handlebars-helpers.js | 10 ++-- .../iotserver/lib/less-rhino-1.7.5.js | 2 +- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js index e9e2b793..d8af22b6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js @@ -83,7 +83,7 @@ var route; var renderStatic = function (unit, path) { if (log.isDebugEnabled()) { - log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a static file "' + path + '"'); + //log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a static file "' + path + '"'); } var staticFile = fuse.getFile(unit, 'public' + path); if (staticFile.isExists() && !staticFile.isDirectory()) { @@ -149,9 +149,9 @@ var route; if (layout !== null) { if (log.isDebugEnabled()) { log.debug( - '[' + requestId + '] request for "' + path + '" will be rendered using layout "' + - layout + '" (defined in "' + mainUnit + '") and zones ' + - stringify(zones) + //'[' + requestId + '] request for "' + path + '" will be rendered using layout "' + + //layout + '" (defined in "' + mainUnit + '") and zones ' + + //stringify(zones) ); } @@ -161,9 +161,9 @@ var route; return true; } else { if (log.isDebugEnabled()) { - log.debug( - '[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' + - 'in any of the units ' + stringify(zones)); + //log.debug( + // '[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' + + // 'in any of the units ' + stringify(zones)); } return false; } @@ -181,7 +181,7 @@ var route; function renderLess(unit, path) { //TODO: fix - incorrect less files makes it respond the old less even if it is nocahce. if (log.isDebugEnabled()) { - log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a less file "' + path + '"'); + //log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a less file "' + path + '"'); } var cacheKey = '/tmp/cached_' + unit + path.replace(/[^\w\.-]/g, '_'); fuseState.currentUnit = unit; @@ -197,7 +197,7 @@ var route; var x = require('less-rhino-1.7.5.js'); x.compile([lessFile.getPath(), cacheKey]); if (log.isDebugEnabled()) { - log.debug('[' + requestId + '] for unit "' + unit + '" request for "' + path + '" is cached as "' + cacheKey + '"'); + //log.debug('[' + requestId + '] for unit "' + unit + '" request for "' + path + '" is cached as "' + cacheKey + '"'); } } } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag index c7731e91..aad26f05 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag @@ -1,10 +1,10 @@ <% -var getPath = File.prototype.getPath; -File.prototype.getPath = function() { - var path = getPath.call(this); - path = path.replace(/\\/g, '/'); - return path; -}; + + + + + + //global object to pass request stat among fuse framework files. var fuseState = { @@ -14,14 +14,14 @@ var fuseState = { currentUnit: null }; -var requestId = function makeId() { - var text = ""; - var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (var i = 0; i < 5; i++) - text += possible.charAt(Math.floor(Math.random() * possible.length)); + + + + + - return text; -}(); + + var fuseDebug = false; //var fuseDebug = true; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js index 7380f57c..134f441c 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js @@ -93,10 +93,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, layout = model.layout; mainUnit = model.name; } else { - log.warn( - '[' + requestId + '] multiple layouts ' + mainUnit + ':' + - layout + ' vs ' + model.name + ':' + model.layout - ); + //log.warn( + // '[' + requestId + '] multiple layouts ' + mainUnit + ':' + + // layout + ' vs ' + model.name + ':' + model.layout + //); } } }; @@ -152,8 +152,8 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, initLookUp(definitions); var model = definitions[lookUpTable[unit]]; if (!model) { - log.warn('[' + requestId + '] unit "' + unit + '" does not exits'); - throw '[' + requestId + '] unit "' + unit + '" does not exits'; + //log.warn('[' + requestId + '] unit "' + unit + '" does not exits'); + //throw '[' + requestId + '] unit "' + unit + '" does not exits'; } return model; }; @@ -219,7 +219,7 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var path = definitionFile.getPath(); if (log.isDebugEnabled()) { - log.debug('[' + requestId + '] reading file "' + path + '"'); + //log.debug('[' + requestId + '] reading file "' + path + '"'); } unitModel.definition = require(path); @@ -351,10 +351,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, while (len--) { if (toDelete[units[len]]) { if (log.isDebugEnabled()) { - log.debug( - '[' + requestId + '] unit "' + units[len] + - '" is overridden by "' + toDelete[units[len]] + '"' - ); + //log.debug( + // '[' + requestId + '] unit "' + units[len] + + // '" is overridden by "' + toDelete[units[len]] + '"' + //); } units.splice(len, 1); } @@ -412,10 +412,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var selfFile = new File(getUnitPath(unitName) + slashPath + selfFileName); if (selfFile.isExists()) { if (log.isDebugEnabled()) { - log.debug( - '[' + requestId + '] for unit "' + unitName + '" file resolved : "' - + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' - ); + //log.debug( + // '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + // + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' + //); } return selfFile; @@ -434,19 +434,19 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var file = new File(getUnitPath(ancestorName) + slashPath + fileName); if (file.isExists()) { if (log.isDebugEnabled()) { - log.debug( - '[' + requestId + '] for unit "' + unitName + '" file resolved : "' - + slashPath + selfFileName + '" -> "' + file.getPath() + '"' - ); + //log.debug( + // '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + // + slashPath + selfFileName + '" -> "' + file.getPath() + '"' + //); } return file; } } if (log.isDebugEnabled()) { - log.debug( - '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' - + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' - ); + //log.debug( + // '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' + // + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' + //); } return selfFile; }; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js index 8c915700..f303d0e0 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js @@ -29,8 +29,8 @@ var getScope = function (unit,configs) { //a warning as the unit author may have forgotten to return a data object if(cbResult===undefined){ cbResult = {}; //Give an empty data object - log.warn('[' + requestId + '] unit "' + unit + '" has a onRequest method which does not return a value.This may lead to the ' - +'unit not been rendered correctly.'); + //log.warn('[' + requestId + '] unit "' + unit + '" has a onRequest method which does not return a value.This may lead to the ' + // +'unit not been rendered correctly.'); } viewModel = cbResult; } @@ -72,7 +72,7 @@ Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) { var unit = unitsToRender[i]; if (Handlebars.innerZonesFromUnit == null || Handlebars.innerZonesFromUnit.unitName == unit.unitName) { var template = fuse.getFile(unit.originUnitName || unit.unitName, '', '.hbs'); - log.debug('[' + requestId + '] for zone "' + zone + '" including template :"' + template.getPath() + '"'); + //log.debug('[' + requestId + '] for zone "' + zone + '" including template :"' + template.getPath() + '"'); result += Handlebars.compileFile(template)(getScope(unit.unitName, zoneContent.data.root)); } } @@ -157,7 +157,7 @@ Handlebars.registerHelper('unit', function (unitName,options) { //TODO warn when unspecified decencies are included. fuseState.currentZone.push('main'); var template = fuse.getFile(baseUnit, '', '.hbs'); - log.debug('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); + //log.debug('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); var result = new Handlebars.SafeString(Handlebars.compileFile(template)(getScope(baseUnit,templateConfigs))); fuseState.currentZone.pop(); return result; @@ -176,7 +176,7 @@ Handlebars.compileFile = function (file) { } f.open('r'); - log.debug('[' + requestId + '] reading file "' + f.getPath() + '"'); + //log.debug('[' + requestId + '] reading file "' + f.getPath() + '"'); var content = f.readAll().trim(); f.close(); var compiled = Handlebars.compile(content); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js index 4a191ca4..b9d609e9 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js @@ -14,7 +14,7 @@ function readFile(name) { var pathInfo = fuse.toRelativePath(name); f = fuse.getFile(pathInfo.unit, pathInfo.path); } - log.debug('[' + requestId + '] opening less file : "' + f.getPath() + '"'); + //log.debug('[' + requestId + '] opening less file : "' + f.getPath() + '"'); f.open('r'); return f.readAll(); }