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) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
var items []*model.GameItem
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
@ -51,12 +51,14 @@ func Crawl(logger *zap.Logger) {
|
||||
for _, game := range games {
|
||||
ids = append(ids, game.ID)
|
||||
}
|
||||
|
||||
var infos []*model.GameInfo
|
||||
if len(ids) != 0 {
|
||||
items, err := db.GetGameItemsByIDs(ids)
|
||||
if err != nil {
|
||||
logger.Error("Failed to get game items", zap.Error(err))
|
||||
return
|
||||
}
|
||||
var infos []*model.GameInfo
|
||||
for _, game := range items {
|
||||
info, err := db.GetGameInfoByGameItemID(game.ID)
|
||||
if err != nil {
|
||||
@ -66,6 +68,8 @@ func Crawl(logger *zap.Logger) {
|
||||
info.Games = append(info.Games, game)
|
||||
infos = append(infos, info)
|
||||
}
|
||||
}
|
||||
|
||||
for _, u := range config.Config.Webhooks.CrawlTask {
|
||||
_, err := url.Parse(u)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user