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) {
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 + '"');
}
}
}

@ -1,10 +1,10 @@
<%
var getPath = File.prototype.getPath;
File.prototype.getPath = function() {
var path = getPath.call(this);
path = path.replace(/\\/g, '/');
return path;
};
<!--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));
<!--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;
}();
<!--return text;-->
<!--}();-->
var fuseDebug = false;
//var fuseDebug = true;

@ -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;
};

@ -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);

@ -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();
}

Loading…
Cancel
Save