Unverified Commit f97db970 authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Remove hacky cache and begin process for redis

parent 801d8a38
......@@ -7,7 +7,7 @@ config.siteDescription = "A simple application to add your class schedule to cal
// MongoDB config
config.mongoDBURL = 'mongodb://localhost/schedules';
config.ReloadDB = false;
config.ReloadDB = true;
config.schoolSlugs = {
// Slug: Long Name
......
......@@ -24,33 +24,13 @@ router.get('/api/json/classes/:SEMSLUG', function(req, res, next) {
// find each person with matching slug
var query = Semester.findOne({ 'slug': slug });
query.select('-_id -classes._id -classes.session_templates._id');
query.exec(function (err, semester) {
query.lean().exec(function (err, semester) {
if (err || (! semester)) {
res.json({
'results' : 'error, try something different'
})
}
else {
if (jsonSlugCache.slugs.length > 10) {
var leastUsedAmount = jsonSlugCache[jsonSlugCache.slugs[0]].timesUsed;
var leastUsed = 0;
for (var i = 0; i < jsonSlugCache.slugs.length; i++) {
var amountUsed = jsonSlugCache[jsonSlugCache.slugs[i]].timesUsed;
if (amountUsed < leastUsedAmount) {
leastUsedAmount = amountUsed;
leastUsed = i;
}
}
delete jsonSlugCache[jsonSlugCache.slugs[leastUsed]];
jsonSlugCache.slugs.splice(leastUsed, 1);
}
jsonSlugCache[slug] = {
'timesUsed' : 1
}
jsonSlugCache[slug].value = JSON.stringify(semester);
jsonSlugCache.slugs.push(slug);
res.send(jsonSlugCache[slug].value);
}
else {res.json(semester);}
})
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment