Skip to content

Commit

Permalink
feat: added multi-spider git
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 29, 2024
1 parent 0b3fbcf commit 8ebfda7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/controllers/spider_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ func getSpiderListWithStats(c *gin.Context) {

// ids
var ids []primitive.ObjectID
var gitIds []primitive.ObjectID
for _, s := range spiders {
ids = append(ids, s.Id)
if !s.GitId.IsZero() {
gitIds = append(gitIds, s.GitId)
}
}

// total count
Expand Down Expand Up @@ -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
var data []models.SpiderV2
for _, s := range spiders {
Expand All @@ -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
data = append(data, s)
}
Expand Down

0 comments on commit 8ebfda7

Please sign in to comment.