2018-04-20 20:46:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/aerogo/nano"
|
|
|
|
"github.com/animenotifier/arn"
|
2019-03-30 06:39:40 +00:00
|
|
|
"github.com/blitzprog/color"
|
2018-04-20 20:46:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Deleting old sessions")
|
|
|
|
|
|
|
|
defer color.Green("Finished.")
|
|
|
|
defer arn.Node.Close()
|
|
|
|
|
|
|
|
// threshold := time.Now().Add(-6 * 30 * 24 * time.Hour).Format(time.RFC3339)
|
|
|
|
count := 0
|
|
|
|
total := 0
|
|
|
|
|
|
|
|
for session := range streamSessions() {
|
|
|
|
data := *session
|
|
|
|
// created := data["created"].(string)
|
|
|
|
|
|
|
|
if data["userId"] == nil { // created < threshold
|
|
|
|
arn.DB.Delete("Session", data["sid"].(string))
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
|
|
|
total++
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Deleted %d / %d sessions.\n", count, total)
|
|
|
|
}
|
|
|
|
|
|
|
|
func streamSessions() chan *arn.Session {
|
|
|
|
channel := make(chan *arn.Session, nano.ChannelBufferSize)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for obj := range arn.DB.All("Session") {
|
|
|
|
channel <- obj.(*arn.Session)
|
|
|
|
}
|
|
|
|
|
|
|
|
close(channel)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return channel
|
|
|
|
}
|