do one api call for template configs rather than two on cold load

v1.18.x
psychobunny 11 years ago
parent 631edc92d3
commit a880ac6e9f

@ -329,9 +329,9 @@ var ajaxify = ajaxify || {};
templates.registerLoader(ajaxify.loadTemplate);
$.when($.getJSON(RELATIVE_PATH + '/templates/config.json'), $.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
templatesConfig = config_data[0];
availableTemplates = templates_data[0];
$.getJSON(RELATIVE_PATH + '/api/get_templates_listing', function (data) {
templatesConfig = data.templatesConfig;
availableTemplates = data.availableTemplates;
app.load();
});

@ -135,10 +135,10 @@ function getModerators(req, res, next) {
});
}
var templatesListingCache = [];
var templatesListingCache = {};
function getTemplatesListing(req, res, next) {
if (templatesListingCache.length) {
if (templatesListingCache.availableTemplates && templatesListingCache.templatesConfig) {
return res.json(templatesListingCache);
}
@ -148,11 +148,15 @@ function getTemplatesListing(req, res, next) {
},
extended: function(next) {
plugins.fireHook('filter:templates.get_virtual', [], next);
}
},
config: function(next) {
fs.readFile(path.join(nconf.get('views_dir'), 'config.json'), next);
},
}, function(err, results) {
if (err) {
return next(err);
}
var data = [];
data = results.views.filter(function(value, index, self) {
return self.indexOf(value) === index;
@ -161,8 +165,13 @@ function getTemplatesListing(req, res, next) {
});
data = data.concat(results.extended);
templatesListingCache = data;
res.json(data);
templatesListingCache = {
availableTemplates: data,
templatesConfig: results.config
};
res.json(templatesListingCache);
});
}

Loading…
Cancel
Save