Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runs get to use cursor-based pagination #273

Merged
merged 10 commits into from
Aug 27, 2024
6 changes: 0 additions & 6 deletions pkg/runs/runsDownload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/http"
"net/http/httptest"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -237,10 +236,7 @@ func WriteMockRasRunsResponse(
writer.Header().Set("Content-Type", "application/json")

values := req.URL.Query()
pageRequestedStr := values.Get("page")
runNameQueryParameter := values.Get("runname")
pageRequested, _ := strconv.Atoi(pageRequestedStr)
assert.Equal(t, pageRequested, 1)

assert.Equal(t, runNameQueryParameter, runName)

Expand All @@ -254,9 +250,7 @@ func WriteMockRasRunsResponse(

writer.Write([]byte(fmt.Sprintf(`
{
"pageNumber": 1,
"pageSize": 1,
"numPages": 1,
"amountOfRuns": %d,
"runs":[ %s ]
}`, len(runResultStrings), combinedRunResultStrings)))
Expand Down
12 changes: 8 additions & 4 deletions pkg/runs/runsGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func GetRunsFromRestApi(
var pageNumberWanted int32 = 1
gotAllResults := false
var restApiVersion string
var pageCursor string

restApiVersion, err = embedded.GetGalasactlRestApiVersion()

Expand All @@ -232,7 +233,7 @@ func GetRunsFromRestApi(
var runData *galasaapi.RunResults
var httpResponse *http.Response
log.Printf("Requesting page '%d' ", pageNumberWanted)
apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion)
apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion).IncludeCursor("true")
if fromAgeMins != 0 {
apicall = apicall.From(fromTime)
}
Expand All @@ -251,8 +252,10 @@ func GetRunsFromRestApi(
if shouldGetActive {
apicall = apicall.Status(activeStatusNames)
}
apicall = apicall.Page(pageNumberWanted)
apicall = apicall.Sort("to:desc")
if pageCursor != "" {
apicall = apicall.Cursor(pageCursor)
}
apicall = apicall.Sort("from:desc")
runData, httpResponse, err = apicall.Execute()

if err != nil {
Expand All @@ -271,9 +274,10 @@ func GetRunsFromRestApi(
results = append(results, runsOnThisPage...)

// Have we processed the last page ?
if pageNumberWanted == runData.GetNumPages() {
if !runData.HasNextCursor() || len(runsOnThisPage) < int(runData.GetPageSize()) {
gotAllResults = true
} else {
pageCursor = runData.GetNextCursor()
pageNumberWanted++
}
}
Expand Down
Loading