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

Feat/add query limit #597

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Feat/add query limit #597

merged 4 commits into from
Mar 12, 2024

Conversation

ccamel
Copy link
Member

@ccamel ccamel commented Mar 11, 2024

This PR introduces an additional (optional) parameter limit to set the desired limit on the number of responses for a Ask 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 the max_result_count parameter of the module.

Summary by CodeRabbit

  • New Features

    • Added a limit option to query requests, allowing users to specify the maximum number of solutions returned.
  • Bug Fixes

    • Fixed an issue where the variables field in answers was incorrectly handled as non-nullable.
  • Tests

    • Updated test cases to support the new maximum result count limit in queries.

Field Answer.Variables is a repeated non-nullable native type, so
nullable=false has no effect.
@ccamel ccamel self-assigned this Mar 11, 2024
Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Walkthrough

These updates introduce a new limit feature across various components to control the number of solutions returned by queries. Modifications include adding a limit field in request messages, adjusting message types, enhancing function logic to respect these limits, and updating tests to verify the new behavior. The changes aim to improve query efficiency and customization, allowing users to specify maximum result counts.

Changes

File Path Change Summary
proto/logic/.../query.proto Added limit field to QueryServiceAskRequest for specifying max solutions; default value handling.
proto/logic/.../types.proto Modified Answer message's variables field to remove (gogoproto.nullable) = false.
x/logic/keeper/grpc_query_ask.go, x/logic/keeper/interpreter.go Added logic for handling limit in queries, including new imports and parameters.
x/logic/keeper/grpc_query_ask_test.go Introduced maxResultCount in tests for limit handling; adjusted test logic.

🐇✨
A hop, a skip, in code we dip,
To limit queries, a clever tip.
With fields anew, and tests in queue,
We refine our search, to just a few.
🌟📚
In bytes we trust, to find, we must.
A rabbit's touch, in code, a brush.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 8da8f62 and 78ab886.
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 and util imports aligns with the usage of these packages in the modified Ask 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 with sdkmath.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 the Ask 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 the DerefOrDefault 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 the QueryServiceAskRequest message, with a default value handling mechanism, is a crucial part of implementing the new functionality. It's important to ensure that the cosmossdk.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 the limit 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 additional limit parameter and the use of sdkmath.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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 78ab886 and d8881f4.
Files selected for processing (1)
  • docs/proto/logic.md (1 hunks)

docs/proto/logic.md Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4cb0ea6 and 251068f.
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 the QueryServiceAskRequest struct within the Ask method is a direct implementation of the PR's objective to enhance the Ask query functionality by introducing an optional limit 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 the Limit 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 the Limit 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 the sdkmath.Uint type for the new Limit field in the AskQuery 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 the cosmossdk.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 the cosmossdk.io/math package is included with a compatible version.

  • 15-15: Adding the Limit field of type *sdkmath.Uint to the AskQuery struct is a crucial part of implementing the new limit functionality for queries. Using a pointer to sdkmath.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 processes AskQuery instances. This might involve setting a default limit or using the module's max_result_count constraint when the Limit is nil.

docs/proto/logic.md (1)
  • 398-398: The addition of the limit field to QueryServiceAskRequest 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 the limit interacts with max_result_count for comprehensive understanding.

Consider enhancing the documentation with examples or scenarios illustrating the use of the limit field, especially in cases where max_result_count might also play a role.

Copy link
Member

@amimart amimart left a 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 :)

@ccamel ccamel merged commit ac8bc74 into main Mar 12, 2024
19 checks passed
@ccamel ccamel deleted the feat/add-query-limit branch March 12, 2024 07:37
@bot-anik
Copy link
Member

bot-anik commented Apr 2, 2024

🎉 This PR is included in version 7.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants