Skip to content

Commit

Permalink
Update runs get to use cursor-based pagination (#273)
Browse files Browse the repository at this point in the history
* Use cursor-based pagination when getting runs from the API server

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Remove includeCursor query parameter

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Swap cursor condition order

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Turn on includeCursor parameter

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Remove log statement

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Use 'from:desc' as the default sort for runs get

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

---------

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>
Signed-off-by: Aashir Siddiqui <aashir_sidiki@hotmail.com>
  • Loading branch information
eamansour authored and aashir21 committed Sep 18, 2024
1 parent 967d8c8 commit 364a909
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 130 deletions.
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

0 comments on commit 364a909

Please sign in to comment.