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

fix(torii): ensure the variable len is applied #2797

Closed
wants to merge 1 commit into from

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Dec 12, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Improved regex pattern handling for key matching, ensuring correct processing of variable-length patterns.
  • Style

    • Minor adjustments made to comments and formatting for clarity.

@glihm glihm changed the title fix: ensure the variable len is applied fix(torii): ensure the variable len is applied Dec 12, 2024
Copy link

coderabbitai bot commented Dec 12, 2024

Walkthrough

Ohayo, sensei! The recent changes focus on the build_keys_pattern function within the mod.rs file of the gRPC server. The primary modification involves updating the regex pattern construction to ensure that entity keys are prefixed with a slash before the repetition operator. This adjustment enhances the handling of variable-length patterns in queries. Additionally, minor formatting and comment updates were made, but these do not impact the overall functionality or structure of the code.

Changes

File Path Change Summary
crates/torii/grpc/src/server/mod.rs Modified build_keys_pattern function to change regex pattern from keys_pattern += &format!("({})*", KEY_PATTERN); to keys_pattern += &format!("(/{})*", KEY_PATTERN);. Minor comment and formatting adjustments made.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    Client->>Server: Send request with entity keys
    Server->>Server: Process request
    Server->>Server: Build keys pattern
    Server-->>Client: Return response with processed keys
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bcd581e and 1c13dea.

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

1127-1127: Ohayo, sensei! The pattern modification looks good!

The addition of a forward slash before KEY_PATTERN in the variable length case ensures proper key separation in the regex pattern. This change aligns with the expected format where keys should be slash-separated.

Let's verify the pattern construction with some test cases:

✅ Verification successful

Ohayo, sensei! The pattern modification is safe and correct!

The change in build_keys_pattern function adds a forward slash before KEY_PATTERN in the variable length case, which is correct because:

  • The base pattern starts with ^ and joins keys with /
  • For variable length matching, adding (/0x[0-9a-fA-F]+)* ensures proper key separation
  • The pattern is used safely in SQL REGEXP queries with proper parameter binding

The implementation aligns with the test case in entities_test.rs where key patterns are used for entity queries.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the regex pattern construction for different key combinations

# Test: Search for examples of key patterns in tests
rg -A 5 'build_keys_pattern|keys_pattern.*\+=' crates/torii/grpc/src/server/tests.rs

# Test: Search for actual usage of these patterns in queries
rg 'REGEXP.*\?' crates/torii/grpc/src/server/mod.rs

Length of output: 494


Script:

#!/bin/bash
# Let's check the implementation of build_keys_pattern and its usage
ast-grep --pattern 'fn build_keys_pattern($$$) {
  $$$
}'

# Also check for any test files in the crates directory
fd 'test.*\.rs' crates/torii/grpc/src/

# And check for the KEY_PATTERN constant definition
rg 'KEY_PATTERN.*=' crates/torii/grpc/src/

Length of output: 281


Script:

#!/bin/bash
# Let's check the test file for any key pattern related tests
cat crates/torii/grpc/src/server/tests/entities_test.rs

# And let's see the full context of the build_keys_pattern function
rg -B 5 -A 10 'fn build_keys_pattern' crates/torii/grpc/src/server/mod.rs

Length of output: 6009


Script:

#!/bin/bash
# Let's see the complete implementation of build_keys_pattern
rg -B 10 -A 20 'fn build_keys_pattern' crates/torii/grpc/src/server/mod.rs

# And check how the pattern is used in queries
rg -B 3 -A 3 'keys_pattern.*REGEXP' crates/torii/grpc/src/server/mod.rs

Length of output: 1152


🪧 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

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 55.76%. Comparing base (bcd581e) to head (1c13dea).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/server/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2797   +/-   ##
=======================================
  Coverage   55.75%   55.76%           
=======================================
  Files         439      439           
  Lines       55522    55522           
=======================================
+ Hits        30957    30961    +4     
+ Misses      24565    24561    -4     

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

@Larkooo Larkooo closed this Dec 12, 2024
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