2018-11-15 04:04:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/animenotifier/arn"
|
2019-03-30 06:39:40 +00:00
|
|
|
"github.com/blitzprog/color"
|
2018-11-15 04:04:14 +00:00
|
|
|
)
|
|
|
|
|
2018-11-15 05:51:05 +00:00
|
|
|
const maxNotificationsPerUser = 30
|
2018-11-15 04:04:14 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Deleting old notifications")
|
|
|
|
|
|
|
|
defer color.Green("Finished")
|
|
|
|
defer arn.Node.Close()
|
|
|
|
|
2018-11-15 05:51:05 +00:00
|
|
|
count := 0
|
|
|
|
|
2018-11-15 04:04:14 +00:00
|
|
|
for user := range arn.StreamUsers() {
|
2018-11-15 05:51:05 +00:00
|
|
|
notifications := user.Notifications()
|
|
|
|
notificationCount := len(notifications.Items)
|
2018-11-15 04:04:14 +00:00
|
|
|
|
|
|
|
if notificationCount > maxNotificationsPerUser {
|
2018-11-15 05:51:05 +00:00
|
|
|
cut := len(notifications.Items) - maxNotificationsPerUser
|
|
|
|
deletedItems := notifications.Items[:cut]
|
|
|
|
newItems := notifications.Items[cut:]
|
|
|
|
|
|
|
|
for _, notificationID := range deletedItems {
|
|
|
|
arn.DB.Delete("Notification", notificationID)
|
|
|
|
}
|
|
|
|
|
|
|
|
notifications.Items = newItems
|
|
|
|
notifications.Save()
|
|
|
|
|
|
|
|
count += len(deletedItems)
|
2018-11-15 04:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-15 05:51:05 +00:00
|
|
|
|
|
|
|
color.Green("Deleted %d notifications", count)
|
2018-11-15 04:04:14 +00:00
|
|
|
}
|