mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: added multi-spider git
https://github.com/crawlab-team/crawlab/issues/1485
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user