Greatly increase the speed of sitemap by a factor of at least 10 (Nathan, Quincy, and Berkeley pairing).

This commit is contained in:
terakilobyte
2015-04-24 18:57:55 -04:00
parent eaf81fd3f7
commit f79834bec9
2 changed files with 55 additions and 22 deletions

View File

@ -49,53 +49,77 @@ module.exports = {
async.parallel({
users: function(callback) {
User.aggregate()
.group({_id: 1, usernames: { $addToSet: '$profile.username'}})
.match({'profile.username': { $ne: ''}})
.exec(function(err, users) {
if (err) {
debug('User err: ', err);
callback(err);
} else {
callback(null, users[0].usernames);
}
});
},
challenges: function (callback) {
Courseware.find({}, function (err, challenges) {
Courseware.aggregate()
.group({_id: 1, names: { $addToSet: '$name'}})
.exec(function (err, challenges) {
if (err) {
debug('Courseware err: ', err);
callback(err);
} else {
callback(null, challenges);
callback(null, challenges[0].names);
}
});
},
bonfires: function (callback) {
Bonfire.find({}, function (err, bonfires) {
Bonfire.aggregate()
.group({_id: 1, names: { $addToSet: '$name'}})
.exec(function (err, bonfires) {
if (err) {
debug('Bonfire err: ', err);
callback(err);
} else {
callback(null, bonfires);
callback(null, bonfires[0].names);
}
});
},
stories: function (callback) {
Story.find({}, function (err, stories) {
Story.aggregate()
.group({_id: 1, links: {$addToSet: '$link'}})
.exec(function (err, stories) {
if (err) {
debug('Story err: ', err);
callback(err);
} else {
callback(null, stories);
callback(null, stories[0].links);
}
});
},
nonprofits: function (callback) {
Nonprofit.find({}, function (err, nonprofits) {
Nonprofit.aggregate()
.group({_id: 1, names: { $addToSet: '$name'}})
.exec(function (err, nonprofits) {
if (err) {
debug('User err: ', err);
callback(err);
} else {
callback(null, nonprofits);
callback(null, nonprofits[0].names);
}
});
},
fieldGuides: function (callback) {
FieldGuide.find({}, function (err, fieldGuides) {
FieldGuide.aggregate()
.group({_id: 1, names: { $addToSet: '$name'}})
.exec(function (err, fieldGuides) {
if (err) {
debug('User err: ', err);
callback(err);
} else {
callback(null, fieldGuides);
callback(null, fieldGuides[0].names);
}
});
}
@ -108,6 +132,7 @@ module.exports = {
res.render('resources/sitemap', {
appUrl: appUrl,
now: now,
users: results.users,
challenges: results.challenges,
bonfires: results.bonfires,
stories: results.stories,
@ -371,7 +396,6 @@ module.exports = {
})();
},
// todo analyze this function in detail
updateUserStoryPictures: function(userId, picture, username, cb) {
var counter = 0,

View File

@ -32,10 +32,19 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
changefreq daily
priority= 0.8
//- User
each user in users
url
loc #{appUrl}/#{user}
lastmod= now
changefreq daily
priority= 0.9
//- Products
each bonfire in bonfires
url
loc #{appUrl}/bonfires/#{bonfire.name.replace(/\s/g, '-')}
loc #{appUrl}/bonfires/#{bonfire.replace(/\s/g, '-')}
lastmod= now
changefreq weekly
priority= 0.5
@ -43,7 +52,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
//- Challenges
each challenge in challenges
url
loc #{appUrl}/challenges/#{challenge.name.replace(/\s/g, '-')}
loc #{appUrl}/challenges/#{challenge.replace(/\s/g, '-')}
lastmod= now
changefreq weekly
priority= 0.5
@ -51,7 +60,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
//- Stories
each story in stories
url
loc #{appUrl}/stories/#{story.storyLink.replace(/\s/g, '-')}
loc #{appUrl}/stories/#{story.replace(/\s/g, '-')}
lastmod= now
changefreq daily
priority= 0.9
@ -59,7 +68,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
//- Nonprofit
each nonprofit in nonprofits
url
loc #{appUrl}/nonprofits/#{nonprofit.name.replace(/\s/g, '-')}
loc #{appUrl}/nonprofits/#{nonprofit.replace(/\s/g, '-')}
lastmod= now
changefreq daily
priority= 0.9
@ -67,7 +76,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
//- Nonprofit
each fieldGuide in fieldGuides
url
loc #{appUrl}/field-guide/#{fieldGuide.name.replace(/\s/g, '-')}
loc #{appUrl}/field-guide/#{fieldGuide.replace(/\s/g, '-')}
lastmod= now
changefreq daily
priority= 0.9