mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-22 08:40:03 +01:00
27 lines
576 B
Go
27 lines
576 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"time"
|
||
|
|
||
|
"github.com/hashicorp/golang-lru/v2/expirable"
|
||
|
)
|
||
|
|
||
|
type TeamStats struct {
|
||
|
Store map[string]*expirable.LRU[string, string]
|
||
|
}
|
||
|
|
||
|
func (ts *TeamStats) keepStats(statsChan chan PostHogEvent) {
|
||
|
log.Println("starting stats keeper...")
|
||
|
for { // ignore the range warning here - it's wrong
|
||
|
select {
|
||
|
case event := <-statsChan:
|
||
|
token := event.Token
|
||
|
if _, ok := ts.Store[token]; !ok {
|
||
|
ts.Store[token] = expirable.NewLRU[string, string](1000000, nil, time.Second*30)
|
||
|
}
|
||
|
ts.Store[token].Add(event.DistinctId, "much wow")
|
||
|
}
|
||
|
}
|
||
|
}
|