2018-04-11 10:05:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
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-11 10:05:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Deleting unused characters")
|
|
|
|
|
|
|
|
defer color.Green("Finished")
|
|
|
|
defer arn.Node.Close()
|
|
|
|
|
|
|
|
used := map[string]bool{}
|
|
|
|
|
|
|
|
// Check quotes
|
|
|
|
for quote := range arn.StreamQuotes() {
|
|
|
|
used[quote.CharacterID] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check log
|
|
|
|
for entry := range arn.StreamEditLogEntries() {
|
|
|
|
if entry.ObjectType != "Character" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
used[entry.ObjectID] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check anime characters
|
|
|
|
for list := range arn.StreamAnimeCharacters() {
|
|
|
|
for _, animeCharacter := range list.Items {
|
|
|
|
used[animeCharacter.CharacterID] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
characters := []*arn.Character{}
|
|
|
|
|
|
|
|
// Delete unused characters
|
|
|
|
for character := range arn.StreamCharacters() {
|
|
|
|
if used[character.ID] {
|
|
|
|
characters = append(characters, character)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Deleting", character.ID, character)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arn.DB.Clear("Character")
|
|
|
|
|
|
|
|
for _, character := range characters {
|
|
|
|
character.Save()
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(len(used), len(characters))
|
|
|
|
}
|