Skip to content

Commit 4d1e2d3

Browse files
authored
Don't reuse response struct for multiple requests (ktrysmt#191)
A fix was added in ktrysmt#186 for the infinite loop while paging. The problem is that it didn't fix the underlying issue, and the fix actually breaks paging in certain circumstances. For example, if I have 13 repos, and a page size of 10, we'll do 13/10 = 1, which equals the page number of 1, and break without retrieving the second page). The actual problem was that the `responsePaginated` variable was being reused in the loop, and the json decoder doesn't overwrite fields that aren't present in the response, so it was the `Next` field would end up with the value from the previous page, causing the same page to be requested forever.
1 parent ddf9b55 commit 4d1e2d3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{},
324324
var values []interface{}
325325
for {
326326
values = append(values, responsePaginated.Values...)
327-
if responsePaginated.Pagelen == 0 || responsePaginated.Size/responsePaginated.Pagelen <= responsePaginated.Page {
327+
if len(responsePaginated.Next) == 0 {
328328
break
329329
}
330330
newReq, err := http.NewRequest(req.Method, responsePaginated.Next, nil)
@@ -336,6 +336,8 @@ func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{},
336336
if err != nil {
337337
return resBody, err
338338
}
339+
340+
responsePaginated = &Response{}
339341
json.NewDecoder(resp).Decode(responsePaginated)
340342
}
341343
responsePaginated.Values = values

0 commit comments

Comments
 (0)