From 006322f3863f5dabbc9b4051cac6b0f466e37916 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 8 Oct 2014 15:26:18 -0400 Subject: [PATCH] much faster sitemap no need to load all the data, when we only use slug and lastposttime --- src/sitemap.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/sitemap.js b/src/sitemap.js index 288d75bb13..fb36538280 100644 --- a/src/sitemap.js +++ b/src/sitemap.js @@ -5,8 +5,10 @@ var path = require('path'), sm = require('sitemap'), url = require('url'), nconf = require('nconf'), + db = require('./database'), categories = require('./categories'), topics = require('./topics'), + privileges = require('./privileges'), utils = require('../public/src/utils'), sitemap = { obj: undefined, @@ -49,21 +51,33 @@ var path = require('path'), }, function(next) { var topicUrls = []; - topics.getTopicsFromSet(0, 'topics:recent', 0, 49, function(err, data) { + + db.getSortedSetRevRange('topics:recent', 0, 49, function(err, tids) { if (err) { return next(err); } + privileges.topics.filter('read', tids, 0, function(err, tids) { + if (err) { + return next(err); + } + + topics.getTopicsFields(tids, ['slug', 'lastposttime'], function(err, topics) { + if (err) { + return next(err); + } - data.topics.forEach(function(topic) { - topicUrls.push({ - url: path.join('/topic', topic.slug), - lastmodISO: utils.toISOString(topic.lastposttime), - changefreq: 'daily', - priority: '0.6' + topics.forEach(function(topic) { + topicUrls.push({ + url: path.join('/topic', topic.slug), + lastmodISO: utils.toISOString(topic.lastposttime), + changefreq: 'daily', + priority: '0.6' + }); + }); + + next(null, topicUrls); }); }); - - next(null, topicUrls); }); } ], function(err, data) {