Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mattias J Duffy
schedules
Commits
a7e0812e
Unverified
Commit
a7e0812e
authored
Jul 25, 2016
by
Mark Stenglein
Browse files
Merge branch 'addRedis' into 1.0
- Added Redis to npm package file - Added configureation for redis in the project
parents
aa9fb182
1972326f
Changes
5
Hide whitespace changes
Inline
Side-by-side
schedules/app.js
View file @
a7e0812e
...
...
@@ -4,6 +4,7 @@ var logger = require('morgan');
var
cookieParser
=
require
(
'
cookie-parser
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
var
mongoose
=
require
(
'
mongoose
'
);
var
mongooseRedisCache
=
require
(
"
mongoose-redis-cache
"
);
// Load site wide configurations
var
config
=
require
(
'
./config
'
);
...
...
@@ -31,6 +32,8 @@ app.use(express.static(path.join(__dirname, 'public')));
// Connect to mongo
mongoose
.
connect
(
config
.
mongoDBURL
);
mongooseRedisCache
(
mongoose
)
// Populate initial data
var
populateDB
=
require
(
'
./setup/populateDB
'
);
populateDB
();
...
...
schedules/config.js
View file @
a7e0812e
...
...
@@ -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
=
fals
e
;
config
.
ReloadDB
=
tru
e
;
config
.
schoolSlugs
=
{
// Slug: Long Name
...
...
schedules/models/Semester.js
View file @
a7e0812e
...
...
@@ -29,6 +29,8 @@ var semesterSchema = new Schema({
]
});
semesterSchema
.
set
(
'
redisCache
'
,
true
)
// the schema is useless so far
// we need to create a model using it
var
Semester
=
mongoose
.
model
(
'
Semester
'
,
semesterSchema
);
...
...
schedules/package.json
View file @
a7e0812e
...
...
@@ -12,6 +12,7 @@
"express"
:
"~4.13.4"
,
"jade"
:
"~1.11.0"
,
"mongoose"
:
"^4.5.5"
,
"mongoose-redis-cache"
:
"0.0.3"
,
"morgan"
:
"~1.7.0"
,
"node-sass"
:
"^3.8.0"
,
"node-sass-middleware"
:
"0.8.0"
...
...
schedules/routes/index.js
View file @
a7e0812e
...
...
@@ -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
);}
})
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment