Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/pagination/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
}

func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
vals, ok := r.URL.Query()["endCursor"]
var endCursor *string
if ok && len(vals) > 0 {
endCursor = &vals[0]
}

limit := 15

queryCursor := r.FormValue("cursor")
Expand All @@ -249,10 +255,11 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
res.ResultArray = append(res.ResultArray, unhash(i))
}

// output cursor to $.cursor in addition to $.resultArray[(@.length-1)]
if len(res.ResultArray) == limit {
cursor, _ := res.ResultArray[len(res.ResultArray)-1].(string)
res.Cursor = &cursor
} else if endCursor != nil {
res.Cursor = endCursor
}
Comment on lines 258 to 263

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If len(res.ResultArray) == limit && endCursor != nil then we will always fall in the first condition. Is that fine ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we iterate until hit the condition where the page is not full and only then return empty cursor @kanwardeep007


w.Header().Set("Content-Type", "application/json")
Expand All @@ -262,6 +269,7 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
}
}


func HandleLimitOffsetDeepOutputsPage(w http.ResponseWriter, r *http.Request) {
queryLimit := r.FormValue("limit")
queryPage := r.FormValue("page")
Expand Down
Loading