mirror of
https://github.com/bestnite/igdb-database.git
synced 2025-04-27 21:45:54 +08:00
u
This commit is contained in:
parent
21a62de6f2
commit
433165356b
10
db/db.go
10
db/db.go
@ -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) {
|
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()
|
defer cancel()
|
||||||
|
|
||||||
coll := GetInstance().Collections[e]
|
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")
|
return nil, fmt.Errorf("collection not found")
|
||||||
}
|
}
|
||||||
cursor, err := coll.Find(ctx, bson.M{"item.id": bson.M{"$in": ids}})
|
cursor, err := coll.Find(ctx, bson.M{"item.id": bson.M{"$in": ids}})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get items %s: %v", string(e), err)
|
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
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +109,14 @@ func ConvertGame(game *pb.Game) (*model.Game, error) {
|
|||||||
}
|
}
|
||||||
res.Bundles = bundlesIds
|
res.Bundles = bundlesIds
|
||||||
|
|
||||||
|
if game.Cover != nil {
|
||||||
coverId := game.Cover.Id
|
coverId := game.Cover.Id
|
||||||
cover, err := GetItemByIGDBID[pb.Cover](endpoint.EPCovers, coverId)
|
cover, err := GetItemByIGDBID[pb.Cover](endpoint.EPCovers, coverId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res.Cover = cover.Item
|
res.Cover = cover.Item
|
||||||
|
}
|
||||||
|
|
||||||
res.CreatedAt = game.CreatedAt
|
res.CreatedAt = game.CreatedAt
|
||||||
|
|
||||||
@ -147,12 +149,14 @@ func ConvertGame(game *pb.Game) (*model.Game, error) {
|
|||||||
|
|
||||||
res.Franchise = nil
|
res.Franchise = nil
|
||||||
|
|
||||||
|
if game.Franchise != nil {
|
||||||
franchiseId := game.Franchise.Id
|
franchiseId := game.Franchise.Id
|
||||||
franchise, err := GetItemByIGDBID[pb.Franchise](endpoint.EPFranchises, franchiseId)
|
franchise, err := GetItemByIGDBID[pb.Franchise](endpoint.EPFranchises, franchiseId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res.Franchise = franchise.Item
|
res.Franchise = franchise.Item
|
||||||
|
}
|
||||||
|
|
||||||
franchiseIds := make([]uint64, 0, len(game.Franchises))
|
franchiseIds := make([]uint64, 0, len(game.Franchises))
|
||||||
for _, g := range game.Franchises {
|
for _, g := range game.Franchises {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user