2018-04-20 20:46:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/aerogo/nano"
|
2019-04-23 05:45:17 +00:00
|
|
|
"github.com/akyoto/color"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
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
|
|
|
|
}
|