Skip to content

Commit

Permalink
track a user as recurring only if he's not new
Browse files Browse the repository at this point in the history
  • Loading branch information
christianparpart committed Apr 8, 2016
1 parent 75066c0 commit 81e30fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func (service *Service) httpTrack(w http.ResponseWriter, r *http.Request) {
} else {
cookie.Expires = time.Now().Add(service.CookieTTL)
http.SetCookie(w, cookie)
service.RecurringSessions.Touch(cookie.Value)

if !service.NewSessions.Contains(cookie.Value) {
service.RecurringSessions.Touch(cookie.Value)
}
}

service.writeEmptyGif(w, r)
Expand Down
7 changes: 7 additions & 0 deletions tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ func (tracker *Tracker) Debugf(msg string, args ...interface{}) {
}
}

func (tracker *Tracker) Contains(sessionID string) bool {
tracker.bucketMutex.Lock()
_, ok := tracker.buckets[sessionID]
tracker.bucketMutex.Unlock()
return ok
}

func (tracker *Tracker) Touch(sessionID string) {
tracker.bucketMutex.Lock()

Expand Down

0 comments on commit 81e30fd

Please sign in to comment.