dojo
dojo copied to clipboard
refactor(torii): get rid of world class hash
Don't think really think we need to store the world class hash. This removes the dependency of having the world declared before launching torii
Summary by CodeRabbit
-
New Features
- Simplified the instantiation of the SQL object in various functions, enhancing readability and reducing complexity.
-
Bug Fixes
- Streamlined database interactions by removing unnecessary parameters in the SQL constructor, potentially improving performance and reliability.
-
Chores
- Updated SQL migration to restructure the database schema by removing obsolete columns while preserving data integrity.
Walkthrough
Ohayo, sensei! The changes predominantly refine the instantiation process of the Sql object across multiple files, eliminating unnecessary parameters and simplifying import statements. This streamlining enhances code readability and maintainability while preserving functionality. Additionally, a migration script updates the database schema by removing obsolete columns, ensuring efficient data management without disrupting existing operations.
Changes
| Files | Change Summary |
|---|---|
bin/torii/src/main.rs, crates/torii/core/src/sql.rs |
Simplified instantiation of Sql by removing the world_class_hash. Enhanced import section by eliminating unused types. |
crates/torii/core/src/sql_test.rs, crates/torii/graphql/src/tests/metadata_test.rs, crates/torii/graphql/src/tests/mod.rs, crates/torii/graphql/src/tests/subscription_test.rs, crates/torii/grpc/src/server/tests/entities_test.rs, crates/torii/libp2p/src/tests.rs |
Streamlined multiple test functions by removing Felt::ZERO from Sql::new instantiation, improving code clarity. |
crates/torii/migrations/20240815022036_remove_world_class_hash.sql |
Migration script creates a new worlds table without obsolete columns, preserving existing data and ensuring smooth operation. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Application
participant Database
User->>Application: Request data
Application->>Database: Initialize Sql (pool, world_address)
Database-->>Application: Return data
Application-->>User: Send data
sequenceDiagram
participant Migration
participant Database
Migration->>Database: Create worlds_new (id, world_address, created_at)
Migration->>Database: Copy data from worlds to worlds_new
Migration->>Database: Drop old worlds table
Migration->>Database: Rename worlds_new to worlds
Recent review details
Configuration used: .coderabbit.yaml Review profile: CHILL
Commits
Files that changed from the base of the PR and between 00770bd4b83975b54b96783ea8b062c4c5cb3580 and ff488ef11d7131bfdbbffedfff3515ae39ff6928.
Files selected for processing (9)
- bin/torii/src/main.rs (2 hunks)
- crates/torii/core/src/sql.rs (1 hunks)
- crates/torii/core/src/sql_test.rs (4 hunks)
- crates/torii/graphql/src/tests/metadata_test.rs (2 hunks)
- crates/torii/graphql/src/tests/mod.rs (1 hunks)
- crates/torii/graphql/src/tests/subscription_test.rs (5 hunks)
- crates/torii/grpc/src/server/tests/entities_test.rs (2 hunks)
- crates/torii/libp2p/src/tests.rs (1 hunks)
- crates/torii/migrations/20240815022036_remove_world_class_hash.sql (1 hunks)
Files skipped from review due to trivial changes (2)
- bin/torii/src/main.rs
- crates/torii/libp2p/src/tests.rs
Additional comments not posted (8)
crates/torii/migrations/20240815022036_remove_world_class_hash.sql (1)
15-16: Ensure foreign key constraints are properly handled.Disabling foreign key constraints can lead to data integrity issues if not handled carefully. Make sure that all necessary constraints are re-established correctly after the migration.
crates/torii/graphql/src/tests/metadata_test.rs (2)
51-51: Initialization ofSqlobject simplified.The
Sql::newfunction now takes fewer parameters, which simplifies the initialization. Ensure that this change aligns with the updatedSqlclass requirements.
103-103: Initialization ofSqlobject simplified.Similar to the previous test, the
Sql::newfunction call has been simplified. Verify that this change is consistent with the new class design and doesn't affect test coverage.crates/torii/grpc/src/server/tests/entities_test.rs (1)
97-97: SimplifiedSqlinstantiation.The
Sql::newfunction now requires fewer parameters, indicating a refactor. Ensure that this change does not affect the test's ability to validate the intended behavior.crates/torii/graphql/src/tests/mod.rs (1)
347-347: Verify the impact of removingFelt::ZERO.The removal of
Felt::ZEROfrom theSql::newcall might indicate a change in the constructor's requirements. Ensure that this modification doesn't affect the test's logic or expected outcomes.Verification successful
Ohayo, sensei! Let's dig deeper to find the
Sql::newconstructor and understand its changes. I'll run another script to gather more information.
Ohayo, sensei! Let's broaden our search to find where
Sqlis defined or used. I'll run another script to track down its location in the codebase.
Removal of
Felt::ZEROis consistent withSql::newrequirements.The
Sql::newconstructor incrates/torii/core/src/sql.rstakes two parameters:poolandworld_address. The removal ofFelt::ZEROin the test file aligns with this signature and does not impact functionality. The test logic remains sound.
Sql::newmethod:pub async fn new(pool: Pool<Sqlite>, world_address: Felt) -> Result<Self>Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the `Sql::new` constructor changes and its impact. # Test: Search for the `Sql::new` constructor definition and its usage. # Expect: Constructor should support two arguments without affecting functionality. ast-grep --lang rust --pattern 'impl Sql { fn new($_, $_) { $$$ } }'Length of output: 70
Script:
#!/bin/bash # Description: Search for the `Sql` struct and its `new` method with any signature. # Locate the `Sql` struct definition and its methods. ast-grep --lang rust --pattern 'struct Sql { $$$ }' # Search for the `new` method within the `Sql` implementation. ast-grep --lang rust --pattern 'impl Sql { fn new($$$) { $$$ } }'Length of output: 121
Script:
#!/bin/bash # Description: Search for the `Sql` identifier across the entire codebase. # Use ripgrep to find occurrences of `Sql` in the codebase. rg 'Sql' --context 5Length of output: 134541
crates/torii/core/src/sql_test.rs (1)
120-120: Verify the impact of simplifyingSqlinstantiation.The simplification of the
Sqlinstantiation by removing the class hash retrieval enhances readability. Ensure that this change doesn't affect the test logic or expected outcomes.Also applies to: 279-279, 355-355
Verification successful
Ohayo, sensei! Let's dig deeper to verify the
Sql::newconstructor's definition. I'll refine the search to capture anynewfunction within theSqlimplementation to ensure it supports the simplified usage. Please hold on while I gather more information.
Ohayo, sensei! It seems the
Sql::newfunction is playing hide and seek. Let's expand our search to find anyimpl Sqlblocks to track down where this elusive function might be defined. Please bear with me while I gather more information.
Ohayo, sensei! We've tracked down the
Sql::newfunction, and it indeed supports the two-parameter usage seen in the test file. This means the simplification is all good and doesn't affect the test logic or outcomes. No worries here!Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of simplifying `Sql` instantiation. # Test: Search for the `Sql::new` constructor definition and ensure it supports the new usage. # Expect: Constructor should support two arguments without affecting functionality. ast-grep --lang rust --pattern 'impl Sql { fn new($_, $_) { $$$ } }'Length of output: 70
Script:
#!/bin/bash # Description: Refine search for the `Sql::new` constructor to verify its signature. # Test: Search for any `new` function within the `Sql` implementation to verify its parameters. # Expect: Find the correct signature of the `new` function within `Sql`. ast-grep --lang rust --pattern 'impl Sql { fn new($$$) { $$$ } }'Length of output: 67
Script:
#!/bin/bash # Description: Search for any `impl Sql` blocks to locate the `new` function. # Test: Search for any implementation blocks of `Sql` to find the `new` function. # Expect: Locate the implementation of `Sql` and identify the `new` function. ast-grep --lang rust --pattern 'impl Sql { $$$ }'Length of output: 79155
crates/torii/graphql/src/tests/subscription_test.rs (1)
24-24: Verify the impact of removingFelt::ZERO.The removal of
Felt::ZEROfrom theSql::newcall across multiple test functions suggests a change in the constructor's requirements. Ensure that this modification doesn't affect the test logic or expected outcomes.Also applies to: 150-150, 255-255, 319-319, 384-384
crates/torii/core/src/sql.rs (1)
43-52: Ohayo, sensei! Simplification looks good, but verify method usage and schema updates.The removal of the
world_class_hashparameter from thenewmethod simplifies the code, and the SQL query is now more straightforward. Ensure all calls to this method are updated to match the new signature. Additionally, verify that the database schema has been updated to align with the removal of theworld_class_hashcolumn in theworldstable.Verification successful
Ohayo, sensei! Changes verified successfully.
The
Sql::newmethod is consistently used with the updated signature across the codebase, and the database schema has been appropriately updated to remove theworld_class_hashcolumn from theworldstable. Everything is aligned and in order.
Instances of
Sql::newwith the new signature found in:
crates/torii/libp2p/src/tests.rscrates/torii/grpc/src/server/tests/entities_test.rscrates/torii/core/src/sql_test.rscrates/torii/graphql/src/tests/mod.rsbin/torii/src/main.rsSchema updates confirmed in migration scripts:
crates/torii/migrations/20240815022036_remove_world_class_hash.sqlScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `new` match the new signature and check for schema updates. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type rust -A 5 $'Sql::new' # Test: Check for migration scripts or schema updates related to the `worlds` table. rg --type sql $'worlds'Length of output: 9099
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 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
@coderabbitaiin 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
@coderabbitaiin 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 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 as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- 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/schema.v2.json
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.
Codecov Report
Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
Project coverage is 69.58%. Comparing base (
00770bd) to head (ff488ef). Report is 1 commits behind head on main.
| Files | Patch % | Lines |
|---|---|---|
| bin/torii/src/main.rs | 0.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #2298 +/- ##
==========================================
- Coverage 69.60% 69.58% -0.03%
==========================================
Files 352 352
Lines 46031 45991 -40
==========================================
- Hits 32040 32002 -38
+ Misses 13991 13989 -2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.