40 lines
828 B
Go
Raw Normal View History

2018-11-15 04:04:14 +00:00
package main
import (
2019-04-23 05:45:17 +00:00
"github.com/akyoto/color"
2019-04-23 05:52:55 +00:00
"github.com/animenotifier/arn"
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
}