From 17ca1d33fbea6cf21ec1e8a0b5253a760e3ce4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 5 May 2017 15:33:00 -0400 Subject: [PATCH] faster sitemap --- src/sitemap.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/sitemap.js b/src/sitemap.js index 8cd91fec6b..8ed9971e7b 100644 --- a/src/sitemap.js +++ b/src/sitemap.js @@ -19,31 +19,25 @@ var sitemap = { }; sitemap.render = function (callback) { - var numTopics = parseInt(meta.config.sitemapTopics, 10) || 500; + var topicsPerPage = parseInt(meta.config.sitemapTopics, 10) || 500; var returnData = { url: nconf.get('url'), topics: [], }; - var numPages; async.waterfall([ - async.apply(db.getSortedSetRange, 'topics:recent', 0, 1000), - function (tids, next) { - privileges.topics.filterTids('read', tids, 0, next); + function (next) { + db.getObjectField('global', 'topicCount', next); }, - ], function (err, tids) { - if (err) { - numPages = 1; - } else { - numPages = Math.ceil(tids.length / numTopics); - } + function (topicCount, next) { + var numPages = Math.max(0, topicCount / topicsPerPage); + for (var x = 1; x <= numPages; x += 1) { + returnData.topics.push(x); + } - for (var x = 1; x <= numPages; x += 1) { - returnData.topics.push(x); - } - - callback(null, returnData); - }); + next(null, returnData); + }, + ], callback); }; sitemap.getPages = function (callback) {