mirror of
https://github.com/bestnite/igdb-database.git
synced 2025-06-17 02:03:18 +08:00
u
This commit is contained in:
59
main.go
59
main.go
@ -34,8 +34,6 @@ func main() {
|
||||
log.Printf("data fetched")
|
||||
}
|
||||
|
||||
Count()
|
||||
|
||||
if *enableAggregate || *enableReAggregate {
|
||||
log.Printf("aggregating games")
|
||||
aggregateGames()
|
||||
@ -118,63 +116,6 @@ func fetchAndStore[T any](
|
||||
}
|
||||
}
|
||||
|
||||
func Count() {
|
||||
ids, err := db.GetAllItemsIDs[pb.Theme](endpoint.EPThemes)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get all items ids %s: %v", endpoint.EPThemes, err)
|
||||
}
|
||||
|
||||
concurrence := make(chan struct{}, 10)
|
||||
defer close(concurrence)
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
for _, id := range ids {
|
||||
concurrence <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func(id uint64) {
|
||||
defer func() {
|
||||
<-concurrence
|
||||
wg.Done()
|
||||
}()
|
||||
count, err := db.CountTheme(id)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to count theme: %v", err)
|
||||
}
|
||||
log.Printf("theme %d count: %d", id, count)
|
||||
err = db.SaveCount(&db.Count{Theme: id, Count: count})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to save count: %v", err)
|
||||
}
|
||||
}(id)
|
||||
}
|
||||
|
||||
ids, err = db.GetAllItemsIDs[pb.Genre](endpoint.EPGenres)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get all items ids %s: %v", endpoint.EPGenres, err)
|
||||
}
|
||||
for _, id := range ids {
|
||||
concurrence <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func(id uint64) {
|
||||
defer func() {
|
||||
<-concurrence
|
||||
wg.Done()
|
||||
}()
|
||||
count, err := db.CountGenre(id)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to count genre: %v", err)
|
||||
}
|
||||
log.Printf("genre %d count: %d", id, count)
|
||||
err = db.SaveCount(&db.Count{Genre: id, Count: count})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to save count: %v", err)
|
||||
}
|
||||
}(id)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func allFetchAndStore(client *igdb.Client) {
|
||||
if *onlyRefetchGames {
|
||||
fetchAndStore(client.Games)
|
||||
|
Reference in New Issue
Block a user