dojo icon indicating copy to clipboard operation
dojo copied to clipboard

refactor(torii): get rid of world class hash

Open Larkooo opened this issue 1 year ago • 2 comments
trafficstars

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.

Larkooo avatar Aug 15 '24 02:08 Larkooo

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 of Sql object simplified.

The Sql::new function now takes fewer parameters, which simplifies the initialization. Ensure that this change aligns with the updated Sql class requirements.


103-103: Initialization of Sql object simplified.

Similar to the previous test, the Sql::new function 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: Simplified Sql instantiation.

The Sql::new function 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 removing Felt::ZERO.

The removal of Felt::ZERO from the Sql::new call 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::new constructor and understand its changes. I'll run another script to gather more information.


Ohayo, sensei! Let's broaden our search to find where Sql is defined or used. I'll run another script to track down its location in the codebase.


Removal of Felt::ZERO is consistent with Sql::new requirements.

The Sql::new constructor in crates/torii/core/src/sql.rs takes two parameters: pool and world_address. The removal of Felt::ZERO in the test file aligns with this signature and does not impact functionality. The test logic remains sound.

  • Sql::new method: 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 5

Length of output: 134541

crates/torii/core/src/sql_test.rs (1)

120-120: Verify the impact of simplifying Sql instantiation.

The simplification of the Sql instantiation 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::new constructor's definition. I'll refine the search to capture any new function within the Sql implementation to ensure it supports the simplified usage. Please hold on while I gather more information.


Ohayo, sensei! It seems the Sql::new function is playing hide and seek. Let's expand our search to find any impl Sql blocks 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::new function, 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 removing Felt::ZERO.

The removal of Felt::ZERO from the Sql::new call 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_hash parameter from the new method 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 the world_class_hash column in the worlds table.

Verification successful

Ohayo, sensei! Changes verified successfully.

The Sql::new method is consistently used with the updated signature across the codebase, and the database schema has been appropriately updated to remove the world_class_hash column from the worlds table. Everything is aligned and in order.

  • Instances of Sql::new with the new signature found in:

    • crates/torii/libp2p/src/tests.rs
    • crates/torii/grpc/src/server/tests/entities_test.rs
    • crates/torii/core/src/sql_test.rs
    • crates/torii/graphql/src/tests/mod.rs
    • bin/torii/src/main.rs
  • Schema updates confirmed in migration scripts:

    • crates/torii/migrations/20240815022036_remove_world_class_hash.sql
Scripts 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 @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 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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to 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.yaml file 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.

coderabbitai[bot] avatar Aug 15 '24 02:08 coderabbitai[bot]

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.

codecov[bot] avatar Aug 15 '24 02:08 codecov[bot]