Skip to content

Commit 978707d

Browse files
feat(pagination): avoid fetching when has_more: false (#218)
1 parent 1eb61c7 commit 978707d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml

packages/pagination/pagination.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,17 @@ func (r *PageAutoPager[T]) Index() int {
109109
}
110110

111111
type CursorPage[T any] struct {
112-
Data []T `json:"data"`
113-
JSON cursorPageJSON `json:"-"`
114-
cfg *requestconfig.RequestConfig
115-
res *http.Response
112+
Data []T `json:"data"`
113+
HasMore bool `json:"has_more"`
114+
JSON cursorPageJSON `json:"-"`
115+
cfg *requestconfig.RequestConfig
116+
res *http.Response
116117
}
117118

118119
// cursorPageJSON contains the JSON metadata for the struct [CursorPage[T]]
119120
type cursorPageJSON struct {
120121
Data apijson.Field
122+
HasMore apijson.Field
121123
raw string
122124
ExtraFields map[string]apijson.Field
123125
}
@@ -134,6 +136,9 @@ func (r cursorPageJSON) RawJSON() string {
134136
// there is no next page, this function will return a 'nil' for the page value, but
135137
// will not return an error
136138
func (r *CursorPage[T]) GetNextPage() (res *CursorPage[T], err error) {
139+
if !r.JSON.HasMore.IsMissing() && r.HasMore == false {
140+
return nil, nil
141+
}
137142
items := r.Data
138143
if items == nil || len(items) == 0 {
139144
return nil, nil

0 commit comments

Comments
 (0)