fix task.Crawl
This commit is contained in:
parent
1fbe80f0b9
commit
cb68360f2f
@ -231,6 +231,9 @@ func GetGameItemByID(id primitive.ObjectID) (*model.GameItem, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetGameItemsByIDs(ids []primitive.ObjectID) ([]*model.GameItem, error) {
|
func GetGameItemsByIDs(ids []primitive.ObjectID) ([]*model.GameItem, error) {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
var items []*model.GameItem
|
var items []*model.GameItem
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -51,21 +51,25 @@ func Crawl(logger *zap.Logger) {
|
|||||||
for _, game := range games {
|
for _, game := range games {
|
||||||
ids = append(ids, game.ID)
|
ids = append(ids, game.ID)
|
||||||
}
|
}
|
||||||
items, err := db.GetGameItemsByIDs(ids)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("Failed to get game items", zap.Error(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var infos []*model.GameInfo
|
var infos []*model.GameInfo
|
||||||
for _, game := range items {
|
if len(ids) != 0 {
|
||||||
info, err := db.GetGameInfoByGameItemID(game.ID)
|
items, err := db.GetGameItemsByIDs(ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Failed to get game info", zap.Error(err))
|
logger.Error("Failed to get game items", zap.Error(err))
|
||||||
continue
|
return
|
||||||
|
}
|
||||||
|
for _, game := range items {
|
||||||
|
info, err := db.GetGameInfoByGameItemID(game.ID)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Failed to get game info", zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
info.Games = append(info.Games, game)
|
||||||
|
infos = append(infos, info)
|
||||||
}
|
}
|
||||||
info.Games = append(info.Games, game)
|
|
||||||
infos = append(infos, info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range config.Config.Webhooks.CrawlTask {
|
for _, u := range config.Config.Webhooks.CrawlTask {
|
||||||
_, err := url.Parse(u)
|
_, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user