diff options
author | raylu <raylu@mixpanel.com> | 2011-08-09 00:47:37 -0700 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-08-09 00:49:21 -0700 |
commit | c37572b1dc72fb604bd57ffe27d3f1a7d45cdc0e (patch) | |
tree | 2a3d18026c869b8e1ed70d0d0a27cec44005577b /updates.go | |
parent | 4fe97b8a96f7829a84047c35ae92949f35fd42b0 (diff) | |
download | audioaxis-c37572b1dc72fb604bd57ffe27d3f1a7d45cdc0e.tar.xz |
expire old updates
Diffstat (limited to 'updates.go')
-rw-r--r-- | updates.go | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -42,6 +42,7 @@ func addUpdate(pid int, action uint, song *Song) { updateLock.Lock() defer updateLock.Unlock() + // write new update pup := tailUpdates[pid] if pup != nil { pup.Next = update @@ -50,6 +51,15 @@ func addUpdate(pid int, action uint, song *Song) { } tailUpdates[pid] = update + // expire old updates + const expiryTime = 1e9 * 3 * 60 // 3 minutes + pup = headUpdates[pid] + for pup != nil && pup.Timestamp < update.Timestamp - expiryTime { + pup = pup.Next + headUpdates[pid] = pup + } + + // notify listeners listener := listeners[pid] for listener != nil { listener.L <- true |