Added patch to delete old or user-less sessions
This commit is contained in:
parent
175559117d
commit
e3e296fc68
48
patches/delete-old-sessions/delete-old-sessions.go
Normal file
48
patches/delete-old-sessions/delete-old-sessions.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aerogo/nano"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user