Skip to content

Commit 4129f1a

Browse files
committed
bug fix
1 parent c02e61e commit 4129f1a

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

engine/plugins/api/aviato/employees.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ func (ae *employees) query(e *et.Event, ident *dbt.Entity, apikey []string) (*db
108108
oamid := e.Entity.Asset.(*general.Identifier)
109109

110110
page := 1
111+
total := 1
111112
perPage := 50
112-
var total int
113113
var employlist []*employeeResult
114114
loop:
115115
for _, key := range apikey {
116-
for p := page; ; p++ {
116+
for ; page <= total; page++ {
117117
headers := http.Header{"Content-Type": []string{"application/json"}}
118118
headers["Authorization"] = []string{"Bearer " + key}
119119

120120
_ = ae.plugin.rlimit.Wait(context.TODO())
121121
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
122122
defer cancel()
123123

124-
u := fmt.Sprintf("https://data.api.aviato.co/company/%s/employees?perPage=%d&page=%d", oamid.ID, perPage, p)
124+
u := fmt.Sprintf("https://data.api.aviato.co/company/%s/employees?perPage=%d&page=%d", oamid.ID, perPage, page)
125125
resp, err := http.RequestWebPage(ctx, &http.Request{URL: u, Header: headers})
126126
if err != nil || resp.StatusCode != 200 {
127127
continue
@@ -136,15 +136,11 @@ loop:
136136
employlist = append(employlist, &emp)
137137
}
138138

139-
if len(employlist) >= 100 {
140-
break loop
141-
}
142-
143-
page = p
144139
total = result.Pages
145-
if p >= total {
146-
break loop
147-
}
140+
}
141+
142+
if page == total {
143+
break
148144
}
149145
}
150146

0 commit comments

Comments
 (0)