fix task.Crawl

This commit is contained in:
Nite07 2024-11-23 19:44:58 +08:00
parent 1fbe80f0b9
commit cb68360f2f
2 changed files with 18 additions and 11 deletions

View File

@ -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()

View File

@ -51,12 +51,14 @@ func Crawl(logger *zap.Logger) {
for _, game := range games { for _, game := range games {
ids = append(ids, game.ID) ids = append(ids, game.ID)
} }
var infos []*model.GameInfo
if len(ids) != 0 {
items, err := db.GetGameItemsByIDs(ids) items, err := db.GetGameItemsByIDs(ids)
if err != nil { if err != nil {
logger.Error("Failed to get game items", zap.Error(err)) logger.Error("Failed to get game items", zap.Error(err))
return return
} }
var infos []*model.GameInfo
for _, game := range items { for _, game := range items {
info, err := db.GetGameInfoByGameItemID(game.ID) info, err := db.GetGameInfoByGameItemID(game.ID)
if err != nil { if err != nil {
@ -66,6 +68,8 @@ func Crawl(logger *zap.Logger) {
info.Games = append(info.Games, game) info.Games = append(info.Games, game)
infos = append(infos, info) 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 {