much faster sitemap

no need to load all the data, when we only use slug and lastposttime
v1.18.x
barisusakli 10 years ago
parent e1f67052d0
commit 006322f386

@ -5,8 +5,10 @@ var path = require('path'),
sm = require('sitemap'), sm = require('sitemap'),
url = require('url'), url = require('url'),
nconf = require('nconf'), nconf = require('nconf'),
db = require('./database'),
categories = require('./categories'), categories = require('./categories'),
topics = require('./topics'), topics = require('./topics'),
privileges = require('./privileges'),
utils = require('../public/src/utils'), utils = require('../public/src/utils'),
sitemap = { sitemap = {
obj: undefined, obj: undefined,
@ -49,21 +51,33 @@ var path = require('path'),
}, },
function(next) { function(next) {
var topicUrls = []; var topicUrls = [];
topics.getTopicsFromSet(0, 'topics:recent', 0, 49, function(err, data) {
db.getSortedSetRevRange('topics:recent', 0, 49, function(err, tids) {
if (err) { if (err) {
return next(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) { topics.forEach(function(topic) {
topicUrls.push({ topicUrls.push({
url: path.join('/topic', topic.slug), url: path.join('/topic', topic.slug),
lastmodISO: utils.toISOString(topic.lastposttime), lastmodISO: utils.toISOString(topic.lastposttime),
changefreq: 'daily', changefreq: 'daily',
priority: '0.6' priority: '0.6'
});
});
next(null, topicUrls);
}); });
}); });
next(null, topicUrls);
}); });
} }
], function(err, data) { ], function(err, data) {

Loading…
Cancel
Save