Node.js based forum software built for the modern web
optimized widget call by bundling all queries into one for #1428; fixes active users widget crash
psychobunny5b6acbad1e14
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex a649a243f0..bc97a6bac7 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -93,7 +93,7 @@ var ajaxify = ajaxify || {};templates.parse(tpl_url, data, function(template) {translator.translate(template, function(translatedTemplate) {$('#content').html(translatedTemplate);- ajaxify.widgets.render(tpl_url, function() {+ ajaxify.widgets.render(tpl_url, url, function() {if (typeof callback === 'function') {callback();}diff --git a/public/src/widgets.js b/public/src/widgets.jsindex edc4f2bc7e..eb73e95d36 100644--- a/public/src/widgets.js+++ b/public/src/widgets.js@@ -1,5 +1,5 @@"use strict";-/*global ajaxify, socket, templates*/+/*global ajaxify, templates*/(function(ajaxify) {ajaxify.widgets = {};@@ -14,7 +14,7 @@});};- ajaxify.widgets.render = function(tpl_url, callback) {+ ajaxify.widgets.render = function(template, url, callback) {var widgetLocations = ['sidebar', 'footer', 'header'], numLocations;$('#content [widget-area]').each(function() {@@ -29,11 +29,16 @@if (!numLocations) {ajaxify.widgets.reposition();}-+function renderWidgets(location) {- var area = $('#content [widget-area="' + location + '"]');-- $.get(RELATIVE_PATH + '/api/widgets/render/' + tpl_url + '/' + location, function(renderedWidgets) {+ var area = $('#content [widget-area="' + location + '"]'),+ areaData = {+ location: location,+ template: template + '.tpl',+ url: url+ };++ $.get(RELATIVE_PATH + '/api/widgets/render', areaData, function(renderedWidgets) {var html = '';for (var i=0; i<renderedWidgets.length; ++i) {diff --git a/src/controllers/api.js b/src/controllers/api.jsindex f698a348ea..0945ee2c55 100644--- a/src/controllers/api.js+++ b/src/controllers/api.js@@ -81,10 +81,15 @@ apiController.getConfig = function(req, res, next) {apiController.renderWidgets = function(req, res, next) {var uid = req.user ? req.user.uid : 0,area = {- template: req.params.template + '.tpl',- location: req.params.location+ template: req.query.template,+ location: req.query.location,+ url: req.query.url};+ if (!area.template || !area.location) {+ return res.json(200, {});+ }+widgets.render(uid, area, function(err, data) {res.json(200, data);});diff --git a/src/routes/api.js b/src/routes/api.jsindex ead2258e9f..ed165a03c2 100644--- a/src/routes/api.js+++ b/src/routes/api.js@@ -184,7 +184,7 @@ module.exports = function(app, middleware, controllers) {app.use('/api', router);router.get('/config', controllers.api.getConfig);- router.get('/widgets/render/:template/:location/:term?', controllers.api.renderWidgets);+ router.get('/widgets/render', controllers.api.renderWidgets);router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);router.get('/get_templates_listing', getTemplatesListing);diff --git a/src/widgets.js b/src/widgets.jsindex c52bb9298c..b04101fee5 100644--- a/src/widgets.js+++ b/src/widgets.js@@ -18,7 +18,6 @@ var async = require('async'),var rendered = [];-async.parallel({global: function(next) {Widgets.getArea('global', area.location, next);