mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
do one api call for template configs rather than two on cold load
This commit is contained in:
@@ -329,9 +329,9 @@ var ajaxify = ajaxify || {};
|
|||||||
|
|
||||||
templates.registerLoader(ajaxify.loadTemplate);
|
templates.registerLoader(ajaxify.loadTemplate);
|
||||||
|
|
||||||
$.when($.getJSON(RELATIVE_PATH + '/templates/config.json'), $.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
|
$.getJSON(RELATIVE_PATH + '/api/get_templates_listing', function (data) {
|
||||||
templatesConfig = config_data[0];
|
templatesConfig = data.templatesConfig;
|
||||||
availableTemplates = templates_data[0];
|
availableTemplates = data.availableTemplates;
|
||||||
|
|
||||||
app.load();
|
app.load();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -135,10 +135,10 @@ function getModerators(req, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var templatesListingCache = [];
|
var templatesListingCache = {};
|
||||||
|
|
||||||
function getTemplatesListing(req, res, next) {
|
function getTemplatesListing(req, res, next) {
|
||||||
if (templatesListingCache.length) {
|
if (templatesListingCache.availableTemplates && templatesListingCache.templatesConfig) {
|
||||||
return res.json(templatesListingCache);
|
return res.json(templatesListingCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,11 +148,15 @@ function getTemplatesListing(req, res, next) {
|
|||||||
},
|
},
|
||||||
extended: function(next) {
|
extended: function(next) {
|
||||||
plugins.fireHook('filter:templates.get_virtual', [], 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) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = [];
|
var data = [];
|
||||||
data = results.views.filter(function(value, index, self) {
|
data = results.views.filter(function(value, index, self) {
|
||||||
return self.indexOf(value) === index;
|
return self.indexOf(value) === index;
|
||||||
@@ -161,8 +165,13 @@ function getTemplatesListing(req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
data = data.concat(results.extended);
|
data = data.concat(results.extended);
|
||||||
templatesListingCache = data;
|
|
||||||
res.json(data);
|
templatesListingCache = {
|
||||||
|
availableTemplates: data,
|
||||||
|
templatesConfig: results.config
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(templatesListingCache);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user