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

refactor: feedback on offset and count #17682

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
132 changes: 32 additions & 100 deletions api/cosmos/base/query/v1beta1/pagination.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const (
FlagSignMode = "sign-mode"
FlagPageKey = "page-key"
FlagOffset = "offset"
FlagCountTotal = "count-total"
FlagTimeoutHeight = "timeout-height"
FlagKeyAlgorithm = "algo"
FlagKeyType = "key-type"
Expand Down Expand Up @@ -159,7 +158,6 @@ func AddPaginationFlagsToCmd(cmd *cobra.Command, query string) {
cmd.Flags().String(FlagPageKey, "", fmt.Sprintf("pagination page-key of %s to query for", query))
cmd.Flags().Uint64(FlagOffset, 0, fmt.Sprintf("pagination offset of %s to query for", query))
cmd.Flags().Uint64(FlagLimit, 100, fmt.Sprintf("pagination limit of %s to query for", query))
cmd.Flags().Bool(FlagCountTotal, false, fmt.Sprintf("count total number of records in %s to query for", query))
cmd.Flags().Bool(FlagReverse, false, "results are sorted in descending order")
}

Expand Down
10 changes: 4 additions & 6 deletions client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error) {
pageKey, _ := flagSet.GetString(flags.FlagPageKey)
offset, _ := flagSet.GetUint64(flags.FlagOffset)
limit, _ := flagSet.GetUint64(flags.FlagLimit)
countTotal, _ := flagSet.GetBool(flags.FlagCountTotal)
page, _ := flagSet.GetUint64(flags.FlagPage)
reverse, _ := flagSet.GetBool(flags.FlagReverse)

Expand All @@ -67,11 +66,10 @@ func ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error) {
}

return &query.PageRequest{
Key: []byte(pageKey),
Offset: offset,
Limit: limit,
CountTotal: countTotal,
Reverse: reverse,
Key: []byte(pageKey),
Offset: offset,
Limit: limit,
Reverse: reverse,
}, nil
}

Expand Down
11 changes: 0 additions & 11 deletions proto/cosmos/base/query/v1beta1/pagination.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,16 @@
// Foo some_parameter = 1;
// PageRequest pagination = 2;
// }
message PageRequest {

Check failure on line 13 in proto/cosmos/base/query/v1beta1/pagination.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "2" with name "offset" on message "PageRequest" was deleted.

Check failure on line 13 in proto/cosmos/base/query/v1beta1/pagination.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "4" with name "count_total" on message "PageRequest" was deleted.
// key is a value returned in PageResponse.next_key to begin
// querying the next page most efficiently. Only one of offset or key
// should be set.
bytes key = 1;

// offset is a numeric offset that can be used when key is unavailable.
// It is less efficient than using key. Only one of offset or key should
// be set.
uint64 offset = 2;

// limit is the total number of results to be returned in the result page.
// If left empty it will default to a value to be set by each app.
uint64 limit = 3;

// count_total is set to true to indicate that the result set should include
// a count of the total number of items available for pagination in UIs.
// count_total is only respected when offset is used. It is ignored when key
// is set.
bool count_total = 4;

// reverse is set to true if results are to be returned in the descending order.
//
// Since: cosmos-sdk 0.43
Expand Down
8 changes: 0 additions & 8 deletions types/query/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,13 @@ func Paginate(
} else if count == end+1 {
nextKey = iterator.Key()

if !pageRequest.CountTotal {
break
}
}
if iterator.Error() != nil {
return nil, iterator.Error()
}
}

res := &PageResponse{NextKey: nextKey}
if pageRequest.CountTotal {
res.Total = count
}

return res, nil
}
Expand Down Expand Up @@ -152,8 +146,6 @@ func initPageRequestDefaults(pageRequest *PageRequest) *PageRequest {
if pageRequestCopy.Limit == 0 {
pageRequestCopy.Limit = DefaultLimit

// count total results when the limit is zero/not supplied
pageRequestCopy.CountTotal = true
}

return &pageRequestCopy
Expand Down
Loading
Loading