mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	perf: get rid of more calls, fix other profile pages #12632
This commit is contained in:
		| @@ -12,9 +12,9 @@ blocksController.getBlocks = async function (req, res) { | ||||
| 	const resultsPerPage = 50; | ||||
| 	const start = Math.max(0, page - 1) * resultsPerPage; | ||||
| 	const stop = start + resultsPerPage - 1; | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { uid, username, userslug, blocksCount } = payload; | ||||
|  | ||||
| 	const { uid, username, userslug, blocksCount } = await user.getUserFields(res.locals.uid, ['uid', 'username', 'userslug', 'blocksCount']); | ||||
| 	const payload = {}; | ||||
| 	const uids = await user.blocks.list(uid); | ||||
| 	const data = await plugins.hooks.fire('filter:user.getBlocks', { | ||||
| 		uids: uids, | ||||
|   | ||||
| @@ -9,7 +9,8 @@ const meta = require('../../meta'); | ||||
| const categoriesController = module.exports; | ||||
|  | ||||
| categoriesController.get = async function (req, res) { | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const [states, allCategoriesData] = await Promise.all([ | ||||
| 		user.getCategoryWatchState(res.locals.uid), | ||||
| 		categories.buildForSelect(res.locals.uid, 'find', ['descriptionParsed', 'depth', 'slug']), | ||||
| @@ -31,7 +32,6 @@ categoriesController.get = async function (req, res) { | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload.categories = categoriesData; | ||||
| 	payload.title = `[[pages:account/watched-categories, ${username}]]`; | ||||
| 	payload.breadcrumbs = helpers.buildBreadcrumbs([ | ||||
|   | ||||
| @@ -2,7 +2,6 @@ | ||||
|  | ||||
| const db = require('../../database'); | ||||
| const meta = require('../../meta'); | ||||
| const user = require('../../user'); | ||||
| const helpers = require('../helpers'); | ||||
|  | ||||
| const consentController = module.exports; | ||||
| @@ -11,11 +10,10 @@ consentController.get = async function (req, res, next) { | ||||
| 	if (!meta.config.gdpr_enabled) { | ||||
| 		return next(); | ||||
| 	} | ||||
|  | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const consented = await db.getObjectField(`user:${res.locals.uid}`, 'gdpr_consent'); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload.gdpr_consent = parseInt(consented, 10) === 1; | ||||
| 	payload.digest = { | ||||
| 		frequency: meta.config.dailyDigestFreq || 'off', | ||||
|   | ||||
| @@ -15,18 +15,16 @@ followController.getFollowers = async function (req, res, next) { | ||||
| }; | ||||
|  | ||||
| async function getFollow(tpl, name, req, res) { | ||||
| 	const { userData: payload } = res.locals; | ||||
| 	const { | ||||
| 		username, userslug, followerCount, followingCount, | ||||
| 	} = await user.getUserFields(res.locals.uid, [ | ||||
| 		'username', 'userslug', 'followerCount', 'followingCount', | ||||
| 	]); | ||||
| 	} = payload; | ||||
|  | ||||
| 	const page = parseInt(req.query.page, 10) || 1; | ||||
| 	const resultsPerPage = 50; | ||||
| 	const start = Math.max(0, page - 1) * resultsPerPage; | ||||
| 	const stop = start + resultsPerPage - 1; | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload.title = `[[pages:${tpl}, ${username}]]`; | ||||
|  | ||||
| 	const method = name === 'following' ? 'getFollowing' : 'getFollowers'; | ||||
|   | ||||
| @@ -9,7 +9,7 @@ const groupsController = module.exports; | ||||
| groupsController.get = async function (req, res) { | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	const payload = res.locals.userData; | ||||
|  | ||||
| 	let groupsData = await groups.getUserGroups([res.locals.uid]); | ||||
| 	groupsData = groupsData[0]; | ||||
|   | ||||
| @@ -13,19 +13,17 @@ infoController.get = async function (req, res) { | ||||
| 	const start = (page - 1) * itemsPerPage; | ||||
| 	const stop = start + itemsPerPage - 1; | ||||
|  | ||||
| 	const [{ username, userslug }, isPrivileged] = await Promise.all([ | ||||
| 		user.getUserFields(res.locals.uid, ['username', 'userslug']), | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const [isPrivileged, history, sessions, usernames, emails] = await Promise.all([ | ||||
| 		user.isPrivileged(req.uid), | ||||
| 	]); | ||||
| 	const [history, sessions, usernames, emails, notes] = await Promise.all([ | ||||
| 		user.getModerationHistory(res.locals.uid), | ||||
| 		user.auth.getSessions(res.locals.uid, req.sessionID), | ||||
| 		user.getHistory(`user:${res.locals.uid}:usernames`), | ||||
| 		user.getHistory(`user:${res.locals.uid}:emails`), | ||||
| 		getNotes({ uid: res.locals.uid, isPrivileged }, start, stop), | ||||
| 	]); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	const notes = await getNotes({ uid: res.locals.uid, isPrivileged }, start, stop); | ||||
|  | ||||
| 	payload.history = history; | ||||
| 	payload.sessions = sessions; | ||||
|   | ||||
| @@ -177,10 +177,9 @@ async function getPostsFromUserSet(template, req, res) { | ||||
| 	const data = templateToData[template]; | ||||
| 	const page = Math.max(1, parseInt(req.query.page, 10) || 1); | ||||
|  | ||||
| 	const [{ username, userslug }, settings] = await Promise.all([ | ||||
| 		user.getUserFields(res.locals.uid, ['username', 'userslug']), | ||||
| 		user.getSettings(req.uid), | ||||
| 	]); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const settings = await user.getSettings(req.uid); | ||||
|  | ||||
| 	const itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage; | ||||
| 	const start = (page - 1) * itemsPerPage; | ||||
| @@ -207,7 +206,6 @@ async function getPostsFromUserSet(template, req, res) { | ||||
| 	} | ||||
| 	const { itemCount, itemData } = result; | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload[data.type] = itemData[data.type]; | ||||
| 	payload.nextStart = itemData.nextStart; | ||||
|  | ||||
|   | ||||
| @@ -6,13 +6,15 @@ const helpers = require('../helpers'); | ||||
| const sessionController = module.exports; | ||||
|  | ||||
| sessionController.get = async function (req, res) { | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
|  | ||||
| 	const payload = { | ||||
| 		sessions: await user.auth.getSessions(res.locals.uid, req.sessionID), | ||||
| 		title: '[[pages:account/sessions]]', | ||||
| 		breadcrumbs: helpers.buildBreadcrumbs([{ text: username, url: `/user/${userslug}` }, { text: '[[pages:account/sessions]]' }]), | ||||
| 	}; | ||||
| 	payload.sessions = await user.auth.getSessions(res.locals.uid, req.sessionID); | ||||
| 	payload.title = '[[pages:account/sessions]]'; | ||||
| 	payload.breadcrumbs = helpers.buildBreadcrumbs([ | ||||
| 		{ text: username, url: `/user/${userslug}` }, | ||||
| 		{ text: '[[pages:account/sessions]]' }, | ||||
| 	]); | ||||
|  | ||||
| 	res.render('account/sessions', payload); | ||||
| }; | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const db = require('../../database'); | ||||
| const user = require('../../user'); | ||||
| const helpers = require('../helpers'); | ||||
|  | ||||
| const tagsController = module.exports; | ||||
| @@ -10,10 +9,10 @@ tagsController.get = async function (req, res) { | ||||
| 	if (req.uid !== res.locals.uid) { | ||||
| 		return helpers.notAllowed(req, res); | ||||
| 	} | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const tagData = await db.getSortedSetRange(`uid:${res.locals.uid}:followed_tags`, 0, -1); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload.tags = tagData; | ||||
| 	payload.title = `[[pages:account/watched-tags, ${username}]]`; | ||||
| 	payload.breadcrumbs = helpers.buildBreadcrumbs([ | ||||
|   | ||||
| @@ -6,14 +6,14 @@ const nconf = require('nconf'); | ||||
|  | ||||
| const db = require('../../database'); | ||||
| const helpers = require('../helpers'); | ||||
| const user = require('../../user'); | ||||
| const meta = require('../../meta'); | ||||
| const pagination = require('../../pagination'); | ||||
|  | ||||
| const uploadsController = module.exports; | ||||
|  | ||||
| uploadsController.get = async function (req, res) { | ||||
| 	const { username, userslug } = await user.getUserFields(res.locals.uid, ['username', 'userslug']); | ||||
| 	const payload = res.locals.userData; | ||||
| 	const { username, userslug } = payload; | ||||
| 	const page = Math.max(1, parseInt(req.query.page, 10) || 1); | ||||
| 	const itemsPerPage = 25; | ||||
| 	const start = (page - 1) * itemsPerPage; | ||||
| @@ -23,7 +23,6 @@ uploadsController.get = async function (req, res) { | ||||
| 		db.getSortedSetRevRange(`uid:${res.locals.uid}:uploads`, start, stop), | ||||
| 	]); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload.uploads = uploadNames.map(uploadName => ({ | ||||
| 		name: uploadName, | ||||
| 		url: path.resolve(nconf.get('upload_url'), uploadName), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user