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

refactor-opt(torii-grpc): subscriptions no db fetch #2455

Merged
merged 4 commits into from
Sep 20, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Sep 19, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced clarity and structure in entity type handling.
    • Simplified service operations by removing database dependencies.
  • Bug Fixes

    • Improved performance by reducing unnecessary database queries in update processes.
  • Refactor

    • Renamed fields for better semantic meaning in entity queries.
    • Streamlined service initialization and update methods for efficiency.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

Ohayo, sensei! The changes in this pull request involve renaming fields in several structs to improve clarity, specifically changing entity to ty to better reflect their purpose as type descriptors. Additionally, the Service struct in multiple files has been simplified by removing dependencies on database connections and model caches, streamlining the service's construction and functionality. The publish_updates methods have also been refactored to rely on in-memory data rather than database queries, enhancing the overall efficiency of the code.

Changes

Files Change Summary
crates/torii/core/src/query_queue.rs, crates/torii/core/src/sql.rs Renamed entity to ty in DeleteEntityQuery struct and related data structures, reflecting a shift towards a more structured representation of entity types.
crates/torii/grpc/src/server/subscriptions/entity.rs, .../event_message.rs Simplified Service struct by removing Pool<Sqlite> and Arc<ModelCache> dependencies, and refactored publish_updates methods to utilize in-memory data.

Possibly related PRs


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f795c3a and d67dc75.

Files selected for processing (2)
  • crates/torii/grpc/src/server/subscriptions/entity.rs (3 hunks)
  • crates/torii/grpc/src/server/subscriptions/event_message.rs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • crates/torii/grpc/src/server/subscriptions/entity.rs
  • crates/torii/grpc/src/server/subscriptions/event_message.rs

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 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: 2

Outside diff range and nitpick comments (2)
crates/torii/grpc/src/server/subscriptions/event_message.rs (1)

207-207: Consider handling errors more comprehensively in the spawned task

Ohayo, sensei! Currently, if Service::publish_updates returns an error, it's logged but not acted upon. Depending on the criticality of this operation, you might want to implement retry logic or propagate the error to ensure that subscribers consistently receive updates.

crates/torii/grpc/src/server/subscriptions/entity.rs (1)

229-231: Ohayo, sensei! Consider enhancing error handling in publish_updates

Currently, if publish_updates returns an error, it's logged but not otherwise handled. Depending on the criticality, you might want to implement a retry mechanism or propagate the error to ensure reliable operation.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 82a23a5 and 3929494.

Files selected for processing (4)
  • crates/torii/core/src/query_queue.rs (3 hunks)
  • crates/torii/core/src/sql.rs (1 hunks)
  • crates/torii/grpc/src/server/subscriptions/entity.rs (2 hunks)
  • crates/torii/grpc/src/server/subscriptions/event_message.rs (2 hunks)
Files skipped from review due to trivial changes (1)
  • crates/torii/core/src/sql.rs
Additional comments not posted (2)
crates/torii/core/src/query_queue.rs (2)

45-45: Ohayo sensei! The field rename looks good.

The change from entity to ty better reflects the purpose of the field as a type descriptor. This improves code clarity.


118-121: Ohayo sensei! The change in entity type representation is a good move.

Using a structured Struct instance to represent the entity's type improves the code's ability to handle complex types in the future. This is a positive shift towards a more robust type system.

crates/torii/grpc/src/server/subscriptions/entity.rs Outdated Show resolved Hide resolved
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

Commits

Files that changed from the base of the PR and between 3929494 and f795c3a.

Files selected for processing (4)
  • crates/torii/core/src/query_queue.rs (3 hunks)
  • crates/torii/grpc/src/server/mod.rs (1 hunks)
  • crates/torii/grpc/src/server/subscriptions/entity.rs (3 hunks)
  • crates/torii/grpc/src/server/subscriptions/event_message.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/torii/core/src/query_queue.rs
Additional comments not posted (6)
crates/torii/grpc/src/server/subscriptions/event_message.rs (1)

79-80: Ohayo, sensei! The changes to the constructor look good.

The removal of the pool and model_cache parameters simplifies the initialization of the Service struct, aligning with the overall refactoring goal of reducing database dependencies.

crates/torii/grpc/src/server/subscriptions/entity.rs (3)

85-86: Ohayo, sensei! The changes to the new function look good.

The removal of the pool and model_cache parameters simplifies the construction of the Service and reduces its dependencies. This change aligns with the overall goal of refactoring the subscription handling to eliminate the need for database fetching.


Line range hint 89-209: Ohayo, sensei! The refactoring of the publish_updates function looks great.

The removal of the cache and pool parameters simplifies the function and reduces its dependencies on external resources. Using the updated_model directly from the Entity to construct the response eliminates the need for querying the database, potentially improving performance.

The overall logic of the function remains intact, ensuring that subscribers receive updates based on their clauses.


187-192: Ohayo, sensei! Consider using if let to safely handle the Option values.

The past review comment is still valid and applicable to this code segment. Using unwrap() can cause the application to panic if entity.updated_model is None or if as_struct() returns None.

To enhance robustness, refactor the code to safely handle the Option values using if let:

-let model = entity.updated_model.as_ref().unwrap().as_struct().unwrap().clone();
+let model = if let Some(updated_model) = entity.updated_model.as_ref() {
+    if let Some(struct_model) = updated_model.as_struct() {
+        struct_model.clone()
+    } else {
+        // Handle the case where as_struct() returns None
+        // e.g., log an error or skip processing
+        return; // or appropriate error handling
+    }
+} else {
+    // Handle the case where updated_model is None
+    // e.g., log an error or skip processing
+    return; // or appropriate error handling
+};
crates/torii/grpc/src/server/mod.rs (2)

109-113: Ohayo sensei! The service instantiation looks much cleaner now. LGTM!

Simplifying the service constructors by reducing the number of dependencies enhances maintainability and reduces complexity. The changes align with the goal of streamlining the initialization process.


Line range hint 32-38: Skipping review of build_composite_clause as it is not part of the changed code segments.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 42.30769% with 15 lines in your changes missing coverage. Please review.

Project coverage is 68.36%. Comparing base (82a23a5) to head (d67dc75).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ates/torii/grpc/src/server/subscriptions/entity.rs 20.00% 8 Missing ⚠️
...rii/grpc/src/server/subscriptions/event_message.rs 22.22% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2455      +/-   ##
==========================================
+ Coverage   68.29%   68.36%   +0.07%     
==========================================
  Files         365      365              
  Lines       48034    47951      -83     
==========================================
- Hits        32805    32782      -23     
+ Misses      15229    15169      -60     

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

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