feat: added multi-spider git

https://github.com/crawlab-team/crawlab/issues/1485
This commit is contained in:
Marvin Zhang
2024-06-29 15:29:24 +08:00
parent 0b3fbcfed8
commit 8ebfda7377

View File

@@ -108,8 +108,12 @@ func getSpiderListWithStats(c *gin.Context) {
// ids // ids
var ids []primitive.ObjectID var ids []primitive.ObjectID
var gitIds []primitive.ObjectID
for _, s := range spiders { for _, s := range spiders {
ids = append(ids, s.Id) ids = append(ids, s.Id)
if !s.GitId.IsZero() {
gitIds = append(gitIds, s.GitId)
}
} }
// total count // total count
@@ -182,6 +186,22 @@ func getSpiderListWithStats(c *gin.Context) {
} }
} }
// git list
var gits []models.GitV2
if len(gitIds) > 0 && utils.IsPro() {
gits, err = service.NewModelServiceV2[models.GitV2]().GetMany(bson.M{"_id": bson.M{"$in": gitIds}}, nil)
if err != nil {
HandleErrorInternalServerError(c, err)
return
}
}
// cache git list to dict
dictGit := map[primitive.ObjectID]models.GitV2{}
for _, g := range gits {
dictGit[g.Id] = g
}
// iterate list again // iterate list again
var data []models.SpiderV2 var data []models.SpiderV2
for _, s := range spiders { for _, s := range spiders {
@@ -197,6 +217,14 @@ func getSpiderListWithStats(c *gin.Context) {
} }
} }
// git
if !s.GitId.IsZero() && utils.IsPro() {
g, ok := dictGit[s.GitId]
if ok {
s.Git = &g
}
}
// add to list // add to list
data = append(data, s) data = append(data, s)
} }