Greatly increase the speed of sitemap by a factor of at least 10 (Nathan, Quincy, and Berkeley pairing).
This commit is contained in:
@ -49,53 +49,77 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
async.parallel({
|
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) {
|
challenges: function (callback) {
|
||||||
Courseware.find({}, function (err, challenges) {
|
Courseware.aggregate()
|
||||||
|
.group({_id: 1, names: { $addToSet: '$name'}})
|
||||||
|
.exec(function (err, challenges) {
|
||||||
if (err) {
|
if (err) {
|
||||||
debug('Courseware err: ', err);
|
debug('Courseware err: ', err);
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(null, challenges);
|
callback(null, challenges[0].names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
bonfires: function (callback) {
|
bonfires: function (callback) {
|
||||||
Bonfire.find({}, function (err, bonfires) {
|
Bonfire.aggregate()
|
||||||
|
.group({_id: 1, names: { $addToSet: '$name'}})
|
||||||
|
.exec(function (err, bonfires) {
|
||||||
if (err) {
|
if (err) {
|
||||||
debug('Bonfire err: ', err);
|
debug('Bonfire err: ', err);
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(null, bonfires);
|
callback(null, bonfires[0].names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
stories: function (callback) {
|
stories: function (callback) {
|
||||||
Story.find({}, function (err, stories) {
|
Story.aggregate()
|
||||||
|
.group({_id: 1, links: {$addToSet: '$link'}})
|
||||||
|
.exec(function (err, stories) {
|
||||||
if (err) {
|
if (err) {
|
||||||
debug('Story err: ', err);
|
debug('Story err: ', err);
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(null, stories);
|
callback(null, stories[0].links);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
nonprofits: function (callback) {
|
nonprofits: function (callback) {
|
||||||
Nonprofit.find({}, function (err, nonprofits) {
|
Nonprofit.aggregate()
|
||||||
|
.group({_id: 1, names: { $addToSet: '$name'}})
|
||||||
|
.exec(function (err, nonprofits) {
|
||||||
if (err) {
|
if (err) {
|
||||||
debug('User err: ', err);
|
debug('User err: ', err);
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(null, nonprofits);
|
callback(null, nonprofits[0].names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fieldGuides: function (callback) {
|
fieldGuides: function (callback) {
|
||||||
FieldGuide.find({}, function (err, fieldGuides) {
|
FieldGuide.aggregate()
|
||||||
|
.group({_id: 1, names: { $addToSet: '$name'}})
|
||||||
|
.exec(function (err, fieldGuides) {
|
||||||
if (err) {
|
if (err) {
|
||||||
debug('User err: ', err);
|
debug('User err: ', err);
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(null, fieldGuides);
|
callback(null, fieldGuides[0].names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -108,6 +132,7 @@ module.exports = {
|
|||||||
res.render('resources/sitemap', {
|
res.render('resources/sitemap', {
|
||||||
appUrl: appUrl,
|
appUrl: appUrl,
|
||||||
now: now,
|
now: now,
|
||||||
|
users: results.users,
|
||||||
challenges: results.challenges,
|
challenges: results.challenges,
|
||||||
bonfires: results.bonfires,
|
bonfires: results.bonfires,
|
||||||
stories: results.stories,
|
stories: results.stories,
|
||||||
@ -371,7 +396,6 @@ module.exports = {
|
|||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
|
|
||||||
// todo analyze this function in detail
|
|
||||||
updateUserStoryPictures: function(userId, picture, username, cb) {
|
updateUserStoryPictures: function(userId, picture, username, cb) {
|
||||||
|
|
||||||
var counter = 0,
|
var counter = 0,
|
||||||
|
@ -32,10 +32,19 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
|||||||
changefreq daily
|
changefreq daily
|
||||||
priority= 0.8
|
priority= 0.8
|
||||||
|
|
||||||
|
//- User
|
||||||
|
each user in users
|
||||||
|
url
|
||||||
|
loc #{appUrl}/#{user}
|
||||||
|
lastmod= now
|
||||||
|
changefreq daily
|
||||||
|
priority= 0.9
|
||||||
|
|
||||||
|
|
||||||
//- Products
|
//- Products
|
||||||
each bonfire in bonfires
|
each bonfire in bonfires
|
||||||
url
|
url
|
||||||
loc #{appUrl}/bonfires/#{bonfire.name.replace(/\s/g, '-')}
|
loc #{appUrl}/bonfires/#{bonfire.replace(/\s/g, '-')}
|
||||||
lastmod= now
|
lastmod= now
|
||||||
changefreq weekly
|
changefreq weekly
|
||||||
priority= 0.5
|
priority= 0.5
|
||||||
@ -43,7 +52,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
|||||||
//- Challenges
|
//- Challenges
|
||||||
each challenge in challenges
|
each challenge in challenges
|
||||||
url
|
url
|
||||||
loc #{appUrl}/challenges/#{challenge.name.replace(/\s/g, '-')}
|
loc #{appUrl}/challenges/#{challenge.replace(/\s/g, '-')}
|
||||||
lastmod= now
|
lastmod= now
|
||||||
changefreq weekly
|
changefreq weekly
|
||||||
priority= 0.5
|
priority= 0.5
|
||||||
@ -51,7 +60,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
|||||||
//- Stories
|
//- Stories
|
||||||
each story in stories
|
each story in stories
|
||||||
url
|
url
|
||||||
loc #{appUrl}/stories/#{story.storyLink.replace(/\s/g, '-')}
|
loc #{appUrl}/stories/#{story.replace(/\s/g, '-')}
|
||||||
lastmod= now
|
lastmod= now
|
||||||
changefreq daily
|
changefreq daily
|
||||||
priority= 0.9
|
priority= 0.9
|
||||||
@ -59,7 +68,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
|||||||
//- Nonprofit
|
//- Nonprofit
|
||||||
each nonprofit in nonprofits
|
each nonprofit in nonprofits
|
||||||
url
|
url
|
||||||
loc #{appUrl}/nonprofits/#{nonprofit.name.replace(/\s/g, '-')}
|
loc #{appUrl}/nonprofits/#{nonprofit.replace(/\s/g, '-')}
|
||||||
lastmod= now
|
lastmod= now
|
||||||
changefreq daily
|
changefreq daily
|
||||||
priority= 0.9
|
priority= 0.9
|
||||||
@ -67,7 +76,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
|||||||
//- Nonprofit
|
//- Nonprofit
|
||||||
each fieldGuide in fieldGuides
|
each fieldGuide in fieldGuides
|
||||||
url
|
url
|
||||||
loc #{appUrl}/field-guide/#{fieldGuide.name.replace(/\s/g, '-')}
|
loc #{appUrl}/field-guide/#{fieldGuide.replace(/\s/g, '-')}
|
||||||
lastmod= now
|
lastmod= now
|
||||||
changefreq daily
|
changefreq daily
|
||||||
priority= 0.9
|
priority= 0.9
|
||||||
|
Reference in New Issue
Block a user