This commit is contained in:
nite 2025-04-07 01:36:53 +10:00
parent 21a62de6f2
commit 433165356b
2 changed files with 18 additions and 16 deletions

View File

@ -331,7 +331,10 @@ func GetItemByIGDBID[T any](e endpoint.EndpointName, id uint64) (*model.Item[T],
}
func GetItemsByIGDBIDs[T any](e endpoint.EndpointName, ids []uint64) (map[uint64]*model.Item[T], error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(len(ids))*200*time.Millisecond)
if len(ids) == 0 {
return nil, nil
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second+time.Duration(len(ids))*200*time.Millisecond)
defer cancel()
coll := GetInstance().Collections[e]
@ -339,7 +342,6 @@ func GetItemsByIGDBIDs[T any](e endpoint.EndpointName, ids []uint64) (map[uint64
return nil, fmt.Errorf("collection not found")
}
cursor, err := coll.Find(ctx, bson.M{"item.id": bson.M{"$in": ids}})
if err != nil {
return nil, fmt.Errorf("failed to get items %s: %v", string(e), err)
}
@ -362,10 +364,6 @@ func GetItemsByIGDBIDs[T any](e endpoint.EndpointName, ids []uint64) (map[uint64
}
}
if len(res) != len(ids) {
return nil, fmt.Errorf("failed to get all items %s: %v", string(e), err)
}
return res, nil
}

View File

@ -109,12 +109,14 @@ func ConvertGame(game *pb.Game) (*model.Game, error) {
}
res.Bundles = bundlesIds
coverId := game.Cover.Id
cover, err := GetItemByIGDBID[pb.Cover](endpoint.EPCovers, coverId)
if err != nil {
return nil, err
if game.Cover != nil {
coverId := game.Cover.Id
cover, err := GetItemByIGDBID[pb.Cover](endpoint.EPCovers, coverId)
if err != nil {
return nil, err
}
res.Cover = cover.Item
}
res.Cover = cover.Item
res.CreatedAt = game.CreatedAt
@ -147,12 +149,14 @@ func ConvertGame(game *pb.Game) (*model.Game, error) {
res.Franchise = nil
franchiseId := game.Franchise.Id
franchise, err := GetItemByIGDBID[pb.Franchise](endpoint.EPFranchises, franchiseId)
if err != nil {
return nil, err
if game.Franchise != nil {
franchiseId := game.Franchise.Id
franchise, err := GetItemByIGDBID[pb.Franchise](endpoint.EPFranchises, franchiseId)
if err != nil {
return nil, err
}
res.Franchise = franchise.Item
}
res.Franchise = franchise.Item
franchiseIds := make([]uint64, 0, len(game.Franchises))
for _, g := range game.Franchises {