Added delete-unused-characters patch
This commit is contained in:
parent
3cf7523d13
commit
d2de04246c
59
patches/delete-unused-characters/delete-unused-characters.go
Normal file
59
patches/delete-unused-characters/delete-unused-characters.go
Normal file
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
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))
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
@ -1,85 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
color.Yellow("Generating character IDs")
|
||||
// color.Yellow("Generating character IDs")
|
||||
|
||||
defer color.Green("Finished")
|
||||
defer arn.Node.Close()
|
||||
// defer color.Green("Finished")
|
||||
// defer arn.Node.Close()
|
||||
|
||||
allCharacters := arn.FilterCharacters(func(character *arn.Character) bool {
|
||||
return len(character.ID) < len("hw5heOmiR")
|
||||
})
|
||||
// sort.Slice(allCharacters, func(i, j int) bool {
|
||||
// aID, _ := strconv.Atoi(allCharacters[i].ID)
|
||||
// bID, _ := strconv.Atoi(allCharacters[j].ID)
|
||||
|
||||
sort.Slice(allCharacters, func(i, j int) bool {
|
||||
aID, _ := strconv.Atoi(allCharacters[i].ID)
|
||||
bID, _ := strconv.Atoi(allCharacters[j].ID)
|
||||
// return aID < bID
|
||||
// })
|
||||
|
||||
return aID < bID
|
||||
})
|
||||
// // Create map of old IDs to new IDs
|
||||
// idMap := map[string]string{}
|
||||
|
||||
// Create map of old IDs to new IDs
|
||||
idMap := map[string]string{}
|
||||
// for counter, character := range allCharacters {
|
||||
// newID := arn.GenerateID("Character")
|
||||
// fmt.Printf("[%d / %d] Old [%s] New [%s] %s\n", counter+1, len(allCharacters), color.YellowString(character.ID), color.GreenString(newID), character)
|
||||
// arn.DB.Delete("Character", character.ID)
|
||||
// idMap[character.ID] = newID
|
||||
// character.ID = newID
|
||||
// character.Save()
|
||||
// }
|
||||
|
||||
for counter, character := range allCharacters {
|
||||
newID := arn.GenerateID("Character")
|
||||
// // Update quotes
|
||||
// for quote := range arn.StreamQuotes() {
|
||||
// newID, exists := idMap[quote.CharacterID]
|
||||
|
||||
if character.GetMapping("myanimelist/character") == "" {
|
||||
fmt.Printf("[%d / %d] Old [%s] New [%s] %s\n", counter+1, len(allCharacters), color.YellowString(character.ID), color.GreenString(newID), character)
|
||||
}
|
||||
|
||||
idMap[character.ID] = newID
|
||||
character.ID = newID
|
||||
character.Save()
|
||||
}
|
||||
|
||||
// Update quotes
|
||||
for quote := range arn.StreamQuotes() {
|
||||
newID, exists := idMap[quote.CharacterID]
|
||||
|
||||
if exists {
|
||||
quote.CharacterID = newID
|
||||
quote.Save()
|
||||
}
|
||||
}
|
||||
|
||||
// Update log
|
||||
for entry := range arn.StreamEditLogEntries() {
|
||||
if entry.ObjectType != "Character" {
|
||||
continue
|
||||
}
|
||||
|
||||
newID, exists := idMap[entry.ObjectID]
|
||||
|
||||
if exists {
|
||||
entry.ObjectID = newID
|
||||
entry.Save()
|
||||
}
|
||||
}
|
||||
|
||||
// Update anime characters
|
||||
for list := range arn.StreamAnimeCharacters() {
|
||||
modified := false
|
||||
|
||||
for _, animeCharacter := range list.Items {
|
||||
newID, exists := idMap[animeCharacter.CharacterID]
|
||||
|
||||
if exists {
|
||||
animeCharacter.CharacterID = newID
|
||||
modified = true
|
||||
}
|
||||
}
|
||||
|
||||
if modified {
|
||||
list.Save()
|
||||
}
|
||||
}
|
||||
// if exists {
|
||||
// quote.CharacterID = newID
|
||||
// quote.Save()
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Update log
|
||||
// for entry := range arn.StreamEditLogEntries() {
|
||||
// if entry.ObjectType != "Character" {
|
||||
// continue
|
||||
// }
|
||||
|
||||
// newID, exists := idMap[entry.ObjectID]
|
||||
|
||||
// if exists {
|
||||
// entry.ObjectID = newID
|
||||
// entry.Save()
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Update anime characters
|
||||
// for list := range arn.StreamAnimeCharacters() {
|
||||
// modified := false
|
||||
|
||||
// for _, animeCharacter := range list.Items {
|
||||
// newID, exists := idMap[animeCharacter.CharacterID]
|
||||
|
||||
// if exists {
|
||||
// animeCharacter.CharacterID = newID
|
||||
// modified = true
|
||||
// }
|
||||
// }
|
||||
|
||||
// if modified {
|
||||
// list.Save()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -188,7 +188,15 @@ var routeTests = map[string][]string{
|
||||
},
|
||||
|
||||
"/character/:id": []string{
|
||||
"/character/6556",
|
||||
"/character/dfrNQrmmg-",
|
||||
},
|
||||
|
||||
"/kitsu/character/:id": []string{
|
||||
"/kitsu/character/6556",
|
||||
},
|
||||
|
||||
"/mal/character/:id": []string{
|
||||
"/mal/character/498",
|
||||
},
|
||||
|
||||
"/compare/animelist/:nick-1/:nick-2": []string{
|
||||
|
Loading…
Reference in New Issue
Block a user