40 lines
839 B
Go
Raw Normal View History

2018-11-15 13:04:14 +09:00
package main
import (
2019-04-23 14:45:17 +09:00
"github.com/akyoto/color"
2019-06-03 18:32:43 +09:00
"github.com/animenotifier/notify.moe/arn"
2018-11-15 13:04:14 +09:00
)
2018-11-15 14:51:05 +09:00
const maxNotificationsPerUser = 30
2018-11-15 13:04:14 +09:00
func main() {
color.Yellow("Deleting old notifications")
defer color.Green("Finished")
defer arn.Node.Close()
2018-11-15 14:51:05 +09:00
count := 0
2018-11-15 13:04:14 +09:00
for user := range arn.StreamUsers() {
2018-11-15 14:51:05 +09:00
notifications := user.Notifications()
notificationCount := len(notifications.Items)
2018-11-15 13:04:14 +09:00
if notificationCount > maxNotificationsPerUser {
2018-11-15 14:51:05 +09: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 13:04:14 +09:00
}
}
2018-11-15 14:51:05 +09:00
color.Green("Deleted %d notifications", count)
2018-11-15 13:04:14 +09:00
}