mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +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) { | ||||
| 					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(); | ||||
| 							} | ||||
|   | ||||
| @@ -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 + '"]'); | ||||
| 			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 = ''; | ||||
|  | ||||
| 				for (var i=0; i<renderedWidgets.length; ++i) { | ||||
|   | ||||
| @@ -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); | ||||
| 	}); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -18,7 +18,6 @@ var async = require('async'), | ||||
|  | ||||
| 		var rendered = []; | ||||
|  | ||||
|  | ||||
| 		async.parallel({ | ||||
| 			global: function(next) { | ||||
| 				Widgets.getArea('global', area.location, next); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user