mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	optimized widget call by bundling all queries into one for #1428; fixes active users widget crash
also fixes b3819fd076 properly
			
			
This commit is contained in:
		| @@ -93,7 +93,7 @@ var ajaxify = ajaxify || {}; | |||||||
| 				templates.parse(tpl_url, data, function(template) { | 				templates.parse(tpl_url, data, function(template) { | ||||||
| 					translator.translate(template, function(translatedTemplate) { | 					translator.translate(template, function(translatedTemplate) { | ||||||
| 						$('#content').html(translatedTemplate); | 						$('#content').html(translatedTemplate); | ||||||
| 						ajaxify.widgets.render(tpl_url, function() { | 						ajaxify.widgets.render(tpl_url, url, function() { | ||||||
| 							if (typeof callback === 'function') { | 							if (typeof callback === 'function') { | ||||||
| 								callback(); | 								callback(); | ||||||
| 							} | 							} | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
| /*global ajaxify, socket, templates*/ | /*global ajaxify, templates*/ | ||||||
|  |  | ||||||
| (function(ajaxify) { | (function(ajaxify) { | ||||||
| 	ajaxify.widgets = {}; | 	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; | 		var widgetLocations = ['sidebar', 'footer', 'header'], numLocations; | ||||||
|  |  | ||||||
| 		$('#content [widget-area]').each(function() { | 		$('#content [widget-area]').each(function() { | ||||||
| @@ -31,9 +31,14 @@ | |||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		function renderWidgets(location) { | 		function renderWidgets(location) { | ||||||
| 			var area = $('#content [widget-area="' + location + '"]'); | 			var area = $('#content [widget-area="' + location + '"]'), | ||||||
|  | 				areaData = { | ||||||
|  | 					location: location, | ||||||
|  | 					template: template + '.tpl', | ||||||
|  | 					url: url | ||||||
|  | 				}; | ||||||
|  |  | ||||||
| 			$.get(RELATIVE_PATH + '/api/widgets/render/' + tpl_url + '/' + location, function(renderedWidgets) { | 			$.get(RELATIVE_PATH + '/api/widgets/render', areaData, function(renderedWidgets) { | ||||||
| 				var html = ''; | 				var html = ''; | ||||||
|  |  | ||||||
| 				for (var i=0; i<renderedWidgets.length; ++i) { | 				for (var i=0; i<renderedWidgets.length; ++i) { | ||||||
|   | |||||||
| @@ -81,10 +81,15 @@ apiController.getConfig = function(req, res, next) { | |||||||
| apiController.renderWidgets = function(req, res, next) { | apiController.renderWidgets = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0, | 	var uid = req.user ? req.user.uid : 0, | ||||||
| 		area = { | 		area = { | ||||||
| 			template: req.params.template + '.tpl', | 			template: req.query.template, | ||||||
| 			location: req.params.location | 			location: req.query.location, | ||||||
|  | 			url: req.query.url | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
|  | 	if (!area.template || !area.location) { | ||||||
|  | 		return res.json(200, {}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	widgets.render(uid, area, function(err, data) { | 	widgets.render(uid, area, function(err, data) { | ||||||
| 		res.json(200, data); | 		res.json(200, data); | ||||||
| 	}); | 	}); | ||||||
|   | |||||||
| @@ -184,7 +184,7 @@ module.exports =  function(app, middleware, controllers) { | |||||||
| 	app.use('/api', router); | 	app.use('/api', router); | ||||||
|  |  | ||||||
| 	router.get('/config', controllers.api.getConfig); | 	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('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID); | ||||||
| 	router.get('/get_templates_listing', getTemplatesListing); | 	router.get('/get_templates_listing', getTemplatesListing); | ||||||
|   | |||||||
| @@ -18,7 +18,6 @@ var async = require('async'), | |||||||
|  |  | ||||||
| 		var rendered = []; | 		var rendered = []; | ||||||
|  |  | ||||||
|  |  | ||||||
| 		async.parallel({ | 		async.parallel({ | ||||||
| 			global: function(next) { | 			global: function(next) { | ||||||
| 				Widgets.getArea('global', area.location, next); | 				Widgets.getArea('global', area.location, next); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user