From c37572b1dc72fb604bd57ffe27d3f1a7d45cdc0e Mon Sep 17 00:00:00 2001 From: raylu Date: Tue, 9 Aug 2011 00:47:37 -0700 Subject: expire old updates --- updates.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/updates.go b/updates.go index e0917cc..997dc4a 100644 --- a/updates.go +++ b/updates.go @@ -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 -- cgit v1.2.3