-
Notifications
You must be signed in to change notification settings - Fork 126
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
Feat/add query limit #597
Feat/add query limit #597
Conversation
Field Answer.Variables is a repeated non-nullable native type, so nullable=false has no effect.
WalkthroughThese updates introduce a new Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
x/logic/types/query.pb.go
is excluded by:!**/*.pb.go
x/logic/types/types.pb.go
is excluded by:!**/*.pb.go
Files selected for processing (5)
- proto/logic/v1beta2/query.proto (1 hunks)
- proto/logic/v1beta2/types.proto (1 hunks)
- x/logic/keeper/grpc_query_ask.go (2 hunks)
- x/logic/keeper/grpc_query_ask_test.go (10 hunks)
- x/logic/keeper/interpreter.go (2 hunks)
Additional comments: 6
x/logic/keeper/grpc_query_ask.go (3)
- 7-7: The addition of
sdkmath
andutil
imports aligns with the usage of these packages in the modifiedAsk
function. Ensure that these packages are used effectively and that there are no unused imports.Also applies to: 14-14
- 17-17: The
defaultLimits
variable is initialized withsdkmath.OneUint()
, which sets a default limit of 1. This default value is consistent with the PR's objective to allow specifying a maximum number of responses. However, consider documenting the rationale behind choosing 1 as the default limit for better maintainability.- 50-51: The use of
util.DerefOrDefault(req.Limit, defaultLimits)
in theAsk
function effectively applies the user-specified limit or the default limit when processing queries. This approach enhances flexibility and control over query results. Ensure that theDerefOrDefault
method is thoroughly tested, especially for edge cases such as null or extremely large values.proto/logic/v1beta2/query.proto (1)
- 47-54: The addition of the
limit
field to theQueryServiceAskRequest
message, with a default value handling mechanism, is a crucial part of implementing the new functionality. It's important to ensure that thecosmossdk.io/math.Uint
custom type is correctly handled in all parts of the system that process this request. Additionally, consider adding validation to ensure that thelimit
value provided by users is within acceptable bounds to prevent potential abuse or system overload.x/logic/keeper/interpreter.go (1)
- 43-43: The modification to the
execute
method to accept an additionallimit
parameter and the use ofsdkmath.MinUint(limit, *limits.MaxResultCount)
to determine the minimum value between the user-specified limit and the module's maximum result count limit are well-implemented. This ensures that the number of responses adheres to specified constraints. It's important to ensure that this logic is covered by unit tests to validate its correctness under various scenarios.Also applies to: 56-56
x/logic/keeper/grpc_query_ask_test.go (1)
- 37-37: The introduction of the
maxResultCount
field and its usage in test cases to control the maximum number of results returned in queries is a necessary adjustment to test the new limit functionality effectively. It's crucial to ensure that these test cases cover a wide range of scenarios, including edge cases such as limits higher than the number of available results and limits lower than the module's configured maximum result count. Additionally, consider adding tests to verify the behavior when invalid limit values are provided.Also applies to: 88-124, 235-292, 329-364
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d8881f4
to
90c594e
Compare
90c594e
to
251068f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
x/logic/types/query.pb.go
is excluded by:!**/*.pb.go
x/logic/types/types.pb.go
is excluded by:!**/*.pb.go
Files selected for processing (8)
- docs/proto/logic.md (1 hunks)
- proto/logic/v1beta2/query.proto (1 hunks)
- proto/logic/v1beta2/types.proto (1 hunks)
- x/logic/keeper/grpc_query_ask.go (2 hunks)
- x/logic/keeper/grpc_query_ask_test.go (10 hunks)
- x/logic/keeper/interpreter.go (2 hunks)
- x/logic/wasm/query.go (1 hunks)
- x/logic/wasm/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
- proto/logic/v1beta2/query.proto
- proto/logic/v1beta2/types.proto
- x/logic/keeper/grpc_query_ask.go
- x/logic/keeper/grpc_query_ask_test.go
- x/logic/keeper/interpreter.go
Additional comments: 4
x/logic/wasm/query.go (1)
- 30-30: The addition of the
Limit
field to theQueryServiceAskRequest
struct within theAsk
method is a direct implementation of the PR's objective to enhance theAsk
query functionality by introducing an optionallimit
parameter. This change allows users to specify the maximum number of responses they want, which is a valuable feature for controlling the size of query results. The implementation appears correct and aligns with the described functionality. However, it's important to ensure that theLimit
field is properly validated elsewhere in the code to handle cases where it might be set to an invalid value (e.g., negative numbers).Ensure that there is validation for the
Limit
field to handle invalid values gracefully. This might involve checking if theLimit
is within an acceptable range and providing a default value if it's not specified.x/logic/wasm/types.go (2)
- 3-7: The import of the
cosmossdk.io/math
package is necessary for using thesdkmath.Uint
type for the newLimit
field in theAskQuery
struct. This change is appropriate and aligns with the objective of introducing a limit parameter for query functionality. It's important to ensure that this new dependency is properly managed and that the version of thecosmossdk.io/math
package is compatible with other dependencies in the project.Check the project's dependency management file (e.g.,
go.mod
) to ensure that thecosmossdk.io/math
package is included with a compatible version.
- 15-15: Adding the
Limit
field of type*sdkmath.Uint
to theAskQuery
struct is a crucial part of implementing the new limit functionality for queries. Using a pointer tosdkmath.Uint
allows for distinguishing between a limit that is explicitly set to zero and an unset limit, which is a good practice for optional parameters. However, it's important to ensure that the handling of this field accounts for nil pointers to avoid potential runtime panics.Ensure that there is proper handling of the
Limit
field when it is nil, especially in the logic that processesAskQuery
instances. This might involve setting a default limit or using the module'smax_result_count
constraint when theLimit
is nil.docs/proto/logic.md (1)
- 398-398: The addition of the
limit
field toQueryServiceAskRequest
is well-documented, providing clear guidance on its behavior and default value. It's important to ensure that the documentation also includes examples or more detailed explanations on how thelimit
interacts withmax_result_count
for comprehensive understanding.Consider enhancing the documentation with examples or scenarios illustrating the use of the
limit
field, especially in cases wheremax_result_count
might also play a role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
🎉 This PR is included in version 7.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This PR introduces an additional (optional) parameter
limit
to set the desired limit on the number of responses for aAsk
query. This parameter is quite common in data query APIs that can return a set of responses. Naturally, this limit is constrained by the value of themax_result_count
parameter of the module.Summary by CodeRabbit
New Features
Bug Fixes
variables
field in answers was incorrectly handled as non-nullable.Tests