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(grpc): add entity models for returned models #2805

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Dec 13, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced query capabilities with the addition of a new field for entity model identifiers in the Query message.
    • Improved filtering options for entity retrieval based on specified models.
  • Bug Fixes

    • Adjustments made to ensure that entity retrieval methods correctly process the new filtering parameter.
  • Documentation

    • Updated method signatures to reflect the inclusion of the new entity_models parameter in various functions.

Copy link

coderabbitai bot commented Dec 13, 2024

Walkthrough

Ohayo, sensei! This pull request introduces a new repeated string field, entity_models, to the Query message in types.proto, enhancing its capabilities for complex queries. Additionally, several methods in the DojoWorld struct within mod.rs are updated to accept this new parameter, allowing for more refined entity filtering based on model identifiers. The changes encompass adjustments in method signatures and internal logic to ensure that only relevant entities are processed and retrieved.

Changes

File Path Change Summary
crates/torii/grpc/proto/types.proto Added field: repeated string entity_models = 6; in Query message.
crates/torii/grpc/src/server/mod.rs Updated methods in DojoWorld: entities_all, fetch_entities, query_by_hashed_keys, query_by_keys, query_by_member, query_by_composite to include entity_models: Vec<String> as a parameter. Adjusted logic to filter entities based on entity_models.
crates/torii/grpc/src/server/tests/entities_test.rs Updated test_entities_queries to include an empty vector as the last argument in the query_by_keys method call.
crates/torii/grpc/src/types/mod.rs Added field entity_models: Vec<String> to the Query struct and updated From<Query> implementation for conversion to proto::types::Query.

Possibly related PRs

Suggested reviewers

  • glihm

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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7817319 and 6c376b7.

📒 Files selected for processing (2)
  • crates/torii/grpc/proto/types.proto (1 hunks)
  • crates/torii/grpc/src/server/mod.rs (18 hunks)
🔇 Additional comments (2)
crates/torii/grpc/src/server/mod.rs (1)

737-743: Avoid using unwrap() to prevent potential panics, sensei

Same issue as earlier, avoid using unwrap() on Felt::from_str(id) to prevent potential panics.

crates/torii/grpc/proto/types.proto (1)

78-78: Looks good, sensei!

No issues found with the addition of the entity_models field to the Query message.

crates/torii/grpc/src/server/mod.rs Show resolved Hide resolved
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 48.93617% with 24 lines in your changes missing coverage. Please review.

Project coverage is 55.74%. Comparing base (8f72aea) to head (453f072).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/server/mod.rs 50.00% 23 Missing ⚠️
crates/torii/grpc/src/types/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2805      +/-   ##
==========================================
- Coverage   55.74%   55.74%   -0.01%     
==========================================
  Files         439      439              
  Lines       55572    55613      +41     
==========================================
+ Hits        30981    31001      +20     
- Misses      24591    24612      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
crates/torii/grpc/src/server/mod.rs (1)

271-271: Refactor entity model ID parsing into a helper function, sensei

The code for converting entity_models into Felt selectors is repeated in multiple places. Consider refactoring this logic into a helper function to improve maintainability.

Also applies to: 703-704, 745-746

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c376b7 and 453f072.

📒 Files selected for processing (3)
  • crates/torii/grpc/src/server/mod.rs (18 hunks)
  • crates/torii/grpc/src/server/tests/entities_test.rs (1 hunks)
  • crates/torii/grpc/src/types/mod.rs (2 hunks)
🔇 Additional comments (8)
crates/torii/grpc/src/server/mod.rs (5)

16-16: Great addition of the import, sensei!

The import of compute_selector_from_tag strengthens the code's functionality.


231-231: Method signature enhancement acknowledged, sensei

Adding entity_models: Vec<String> to entities_all improves entity filtering capabilities.


268-272: Consistent conversion of entity models, sensei

Converting entity_models to Felt selectors is necessary. Ensure consistency across methods.


325-334: Avoid panics by handling potential errors when parsing model IDs, sensei

Using unwrap() on Felt::from_str(id) can cause a panic if id is invalid. It's better to handle the possible Err case to prevent runtime panics.


744-752: ⚠️ Potential issue

Handle potential from_str errors to prevent panics, sensei

Using unwrap() on Felt::from_str(id) may cause panics with invalid strings. Consider error handling to ensure robustness.

Apply this diff to safely handle parsing errors:

-let model_id = Felt::from_str(id).unwrap();
+let model_id = match Felt::from_str(id) {
+    Ok(model_id) => model_id,
+    Err(_) => {
+        // Handle the error, e.g., skip this ID or log the error
+        return Ok(None);
+    }
+};

Likely invalid or redundant comment.

crates/torii/grpc/src/server/tests/entities_test.rs (1)

145-145: Ensuring default entity models in tests, sensei

Passing an empty vector vec![] for entity_models aligns with the updated method signature. Ensure that tests cover cases with and without specified entity models.

crates/torii/grpc/src/types/mod.rs (2)

108-108: Addition of entity_models field strengthens Query struct, sensei

Including entity_models: Vec<String> in the Query struct enhances query capabilities. Ensure serialization and deserialization handle this new field appropriately.


273-273: Ensure proper mapping of entity_models in From implementation, sensei

Mapping entity_models in the From<Query> implementation ensures consistency between internal and external representations.

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Removing empty models is currently breaking the total count. But this total count is not exposed by dojo.c at the moment.

Let's iterate to see how this can be achieved in the future.

@glihm glihm merged commit c730914 into dojoengine:main Dec 13, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants