Node.js based forum software built for the modern web
refactor: move getTopicData call to avoid db calls when its not in cache
Barış Soner Uşaklı252d0df76ccf
diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex 1d8c49205e..6a3eba85c5 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -31,15 +31,17 @@ topicsController.get = async function getTopic(req, res, next) {return next();}let postIndex = parseInt(req.params.post_index, 10) || 1;+ const topicData = await topics.getTopicData(tid);+ if (!topicData) {+ return next();+ }const [userPrivileges,settings,- topicData,rssToken,] = await Promise.all([privileges.topics.get(tid, req.uid),user.getSettings(req.uid),- topics.getTopicData(tid),user.auth.getFeedToken(req.uid),]);@@ -47,7 +49,6 @@ topicsController.get = async function getTopic(req, res, next) {const pageCount = Math.max(1, Math.ceil((topicData && topicData.postcount) / settings.postsPerPage));const invalidPagination = (settings.usePagination && (currentPage < 1 || currentPage > pageCount));if (- !topicData ||userPrivileges.disabled ||invalidPagination ||(topicData.scheduled && !userPrivileges.view_scheduled)@@ -380,16 +381,14 @@ topicsController.pagination = async function (req, res, next) {if (!utils.isNumber(tid)) {return next();}-- const [userPrivileges, settings, topic] = await Promise.all([- privileges.topics.get(tid, req.uid),- user.getSettings(req.uid),- topics.getTopicData(tid),- ]);-+ const topic = await topics.getTopicData(tid);if (!topic) {return next();}+ const [userPrivileges, settings] = await Promise.all([+ privileges.topics.get(tid, req.uid),+ user.getSettings(req.uid),+ ]);if (!userPrivileges.read || !privileges.topics.canViewDeletedScheduled(topic, userPrivileges)) {return helpers.notAllowed(req, res);