-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.coffee
45 lines (39 loc) · 1.04 KB
/
data.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cache = require './cache'
Event = require './models/event'
Tweet = require './models/tweet'
Message = require './models/message'
GitEvent = require './models/gitevent'
ten_minutes = 10 * 60 * 1000
fetchMessages = cache.for ten_minutes, (cb) ->
Message.load cb
fetchTweets = cache.for ten_minutes, (cb) ->
Tweet.load cb
fetchEvents = cache.for ten_minutes, (cb) ->
Event.load cb
fetchGitEvents = cache.for ten_minutes, (cb) ->
GitEvent.loadPushEvents 10, cb
module.exports = {
load: (keys...) ->
return (req, res, next) =>
jobs = keys.length
res.data or= {}
keys.forEach (key) =>
this[key] res.data, () ->
next() if --jobs == 0
messages: (data, cb) ->
fetchMessages (messages) ->
data.messages = messages
cb()
tweets: (data, cb) ->
fetchTweets (tweets) ->
data.tweets = tweets
cb()
events: (data, cb) ->
fetchEvents (events) ->
data.events = events
cb()
gitEvents: (data, cb) ->
fetchGitEvents (events) ->
data.gitEvents = events
cb()
}