fixing jaggery app performance issue

merge-requests/1/head
Rasika Perera 9 years ago
parent 68ced07235
commit 019f077ea4

@ -83,7 +83,7 @@ var route;
var renderStatic = function (unit, path) { var renderStatic = function (unit, path) {
if (log.isDebugEnabled()) { 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); var staticFile = fuse.getFile(unit, 'public' + path);
if (staticFile.isExists() && !staticFile.isDirectory()) { if (staticFile.isExists() && !staticFile.isDirectory()) {
@ -149,9 +149,9 @@ var route;
if (layout !== null) { if (layout !== null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
'[' + requestId + '] request for "' + path + '" will be rendered using layout "' + //'[' + requestId + '] request for "' + path + '" will be rendered using layout "' +
layout + '" (defined in "' + mainUnit + '") and zones ' + //layout + '" (defined in "' + mainUnit + '") and zones ' +
stringify(zones) //stringify(zones)
); );
} }
@ -161,9 +161,9 @@ var route;
return true; return true;
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( //log.debug(
'[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' + // '[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' +
'in any of the units ' + stringify(zones)); // 'in any of the units ' + stringify(zones));
} }
return false; return false;
} }
@ -181,7 +181,7 @@ var route;
function renderLess(unit, path) { function renderLess(unit, path) {
//TODO: fix - incorrect less files makes it respond the old less even if it is nocahce. //TODO: fix - incorrect less files makes it respond the old less even if it is nocahce.
if (log.isDebugEnabled()) { 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, '_'); var cacheKey = '/tmp/cached_' + unit + path.replace(/[^\w\.-]/g, '_');
fuseState.currentUnit = unit; fuseState.currentUnit = unit;
@ -197,7 +197,7 @@ var route;
var x = require('less-rhino-1.7.5.js'); var x = require('less-rhino-1.7.5.js');
x.compile([lessFile.getPath(), cacheKey]); x.compile([lessFile.getPath(), cacheKey]);
if (log.isDebugEnabled()) { 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 + '"');
} }
} }
} }

@ -1,10 +1,10 @@
<% <%
var getPath = File.prototype.getPath; <!--var getPath = File.prototype.getPath;-->
File.prototype.getPath = function() { <!--File.prototype.getPath = function() {-->
var path = getPath.call(this); <!--var path = getPath.call(this);-->
path = path.replace(/\\/g, '/'); <!--path = path.replace(/\\/g, '/');-->
return path; <!--return path;-->
}; <!--};-->
//global object to pass request stat among fuse framework files. //global object to pass request stat among fuse framework files.
var fuseState = { var fuseState = {
@ -14,14 +14,14 @@ var fuseState = {
currentUnit: null currentUnit: null
}; };
var requestId = function makeId() { <!--var requestId = function makeId() {-->
var text = ""; <!--var text = "";-->
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; <!--var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";-->
for (var i = 0; i < 5; i++) <!--for (var i = 0; i < 5; i++)-->
text += possible.charAt(Math.floor(Math.random() * possible.length)); <!--text += possible.charAt(Math.floor(Math.random() * possible.length));-->
return text; <!--return text;-->
}(); <!--}();-->
var fuseDebug = false; var fuseDebug = false;
//var fuseDebug = true; //var fuseDebug = true;

@ -93,10 +93,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
layout = model.layout; layout = model.layout;
mainUnit = model.name; mainUnit = model.name;
} else { } else {
log.warn( //log.warn(
'[' + requestId + '] multiple layouts ' + mainUnit + ':' + // '[' + requestId + '] multiple layouts ' + mainUnit + ':' +
layout + ' vs ' + model.name + ':' + model.layout // layout + ' vs ' + model.name + ':' + model.layout
); //);
} }
} }
}; };
@ -152,8 +152,8 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
initLookUp(definitions); initLookUp(definitions);
var model = definitions[lookUpTable[unit]]; var model = definitions[lookUpTable[unit]];
if (!model) { if (!model) {
log.warn('[' + requestId + '] unit "' + unit + '" does not exits'); //log.warn('[' + requestId + '] unit "' + unit + '" does not exits');
throw '[' + requestId + '] unit "' + unit + '" does not exits'; //throw '[' + requestId + '] unit "' + unit + '" does not exits';
} }
return model; return model;
}; };
@ -219,7 +219,7 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
var path = definitionFile.getPath(); var path = definitionFile.getPath();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug('[' + requestId + '] reading file "' + path + '"'); //log.debug('[' + requestId + '] reading file "' + path + '"');
} }
unitModel.definition = require(path); unitModel.definition = require(path);
@ -351,10 +351,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
while (len--) { while (len--) {
if (toDelete[units[len]]) { if (toDelete[units[len]]) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( //log.debug(
'[' + requestId + '] unit "' + units[len] + // '[' + requestId + '] unit "' + units[len] +
'" is overridden by "' + toDelete[units[len]] + '"' // '" is overridden by "' + toDelete[units[len]] + '"'
); //);
} }
units.splice(len, 1); units.splice(len, 1);
} }
@ -412,10 +412,10 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
var selfFile = new File(getUnitPath(unitName) + slashPath + selfFileName); var selfFile = new File(getUnitPath(unitName) + slashPath + selfFileName);
if (selfFile.isExists()) { if (selfFile.isExists()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( //log.debug(
'[' + requestId + '] for unit "' + unitName + '" file resolved : "' // '[' + requestId + '] for unit "' + unitName + '" file resolved : "'
+ slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' // + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"'
); //);
} }
return selfFile; return selfFile;
@ -434,19 +434,19 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors,
var file = new File(getUnitPath(ancestorName) + slashPath + fileName); var file = new File(getUnitPath(ancestorName) + slashPath + fileName);
if (file.isExists()) { if (file.isExists()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( //log.debug(
'[' + requestId + '] for unit "' + unitName + '" file resolved : "' // '[' + requestId + '] for unit "' + unitName + '" file resolved : "'
+ slashPath + selfFileName + '" -> "' + file.getPath() + '"' // + slashPath + selfFileName + '" -> "' + file.getPath() + '"'
); //);
} }
return file; return file;
} }
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( //log.debug(
'[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' // '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "'
+ slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' // + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"'
); //);
} }
return selfFile; return selfFile;
}; };

@ -29,8 +29,8 @@ var getScope = function (unit,configs) {
//a warning as the unit author may have forgotten to return a data object //a warning as the unit author may have forgotten to return a data object
if(cbResult===undefined){ if(cbResult===undefined){
cbResult = {}; //Give an empty data object 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 ' //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.'); // +'unit not been rendered correctly.');
} }
viewModel = cbResult; viewModel = cbResult;
} }
@ -72,7 +72,7 @@ Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) {
var unit = unitsToRender[i]; var unit = unitsToRender[i];
if (Handlebars.innerZonesFromUnit == null || Handlebars.innerZonesFromUnit.unitName == unit.unitName) { if (Handlebars.innerZonesFromUnit == null || Handlebars.innerZonesFromUnit.unitName == unit.unitName) {
var template = fuse.getFile(unit.originUnitName || unit.unitName, '', '.hbs'); 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)); 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. //TODO warn when unspecified decencies are included.
fuseState.currentZone.push('main'); fuseState.currentZone.push('main');
var template = fuse.getFile(baseUnit, '', '.hbs'); 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))); var result = new Handlebars.SafeString(Handlebars.compileFile(template)(getScope(baseUnit,templateConfigs)));
fuseState.currentZone.pop(); fuseState.currentZone.pop();
return result; return result;
@ -176,7 +176,7 @@ Handlebars.compileFile = function (file) {
} }
f.open('r'); f.open('r');
log.debug('[' + requestId + '] reading file "' + f.getPath() + '"'); //log.debug('[' + requestId + '] reading file "' + f.getPath() + '"');
var content = f.readAll().trim(); var content = f.readAll().trim();
f.close(); f.close();
var compiled = Handlebars.compile(content); var compiled = Handlebars.compile(content);

@ -14,7 +14,7 @@ function readFile(name) {
var pathInfo = fuse.toRelativePath(name); var pathInfo = fuse.toRelativePath(name);
f = fuse.getFile(pathInfo.unit, pathInfo.path); 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'); f.open('r');
return f.readAll(); return f.readAll();
} }

Loading…
Cancel
Save