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-tokens-graphql): returns tokens balances with no metadata #2764

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Dec 5, 2024

Summary by CodeRabbit

  • New Features

    • Improved token balance querying by simplifying conditions.
    • Enhanced error handling for ERC721 token metadata to prevent parsing errors with default values.
  • Bug Fixes

    • Resolved potential issues related to empty metadata strings during token balance fetching.
  • Chores

    • Updated workflow to include error handling in cache management steps, allowing the workflow to continue despite potential cache movement failures.

@glihm glihm changed the title fix(torii-tokens-graphql): returns tokens balances even with empty me… fix(torii-tokens-graphql): returns tokens balances with no metadata Dec 5, 2024
Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

Ohayo, sensei! This pull request introduces modifications to the ErcBalanceObject in the token_balance.rs file. The conditions for querying token balances have been simplified by removing the metadata length check, focusing solely on the account_address. Additionally, the handling of ERC721 token metadata has been refactored to include default values when the metadata string is empty, enhancing error handling. While the overall control flow remains the same, these changes aim to improve clarity and robustness in the code.

Changes

File Path Change Summary
crates/torii/graphql/src/object/erc/token_balance.rs Simplified querying conditions for token balances by removing metadata length check; refactored ERC721 metadata handling to assign default values when metadata is empty.
.github/workflows/preview.yml Modified cache movement commands to include error handling, allowing workflow to continue even if cache operations fail.

Possibly related PRs


🪧 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: 1

🧹 Outside diff range and nitpick comments (1)
crates/torii/graphql/src/object/erc/token_balance.rs (1)

258-258: Consider extracting image path template to configuration

The image path format {token_id}/image appears to be hardcoded. Consider moving this to a configuration value for better maintainability.

+ const TOKEN_IMAGE_PATH_TEMPLATE: &str = "{}/image";
+
  // Later in the code
- let image_path = format!("{}/{}", token_id.join("/"), "image");
+ let image_path = format!(TOKEN_IMAGE_PATH_TEMPLATE, token_id.join("/"));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ffc9259 and 09937d9.

📒 Files selected for processing (1)
  • crates/torii/graphql/src/object/erc/token_balance.rs (2 hunks)
🔇 Additional comments (1)
crates/torii/graphql/src/object/erc/token_balance.rs (1)

106-106: Ohayo! The simplified WHERE clause looks good, sensei!

The removal of the metadata length check from the conditions is a positive change as token balances should be returned regardless of metadata presence.

Comment on lines +247 to +249
let metadata: serde_json::Value =
serde_json::from_str(&metadata_str).expect("metadata is always json");
let metadata_name =
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving error handling for metadata parsing, sensei!

The .expect("metadata is always json") could lead to a panic if the metadata is malformed. Consider using a more graceful error handling approach.

-    let metadata: serde_json::Value =
-        serde_json::from_str(&metadata_str).expect("metadata is always json");
+    let metadata: serde_json::Value = match serde_json::from_str(&metadata_str) {
+        Ok(value) => value,
+        Err(e) => {
+            warn!("Failed to parse metadata JSON: {}", e);
+            return (String::new(), None, None, None, String::new());
+        }
+    };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let metadata: serde_json::Value =
serde_json::from_str(&metadata_str).expect("metadata is always json");
let metadata_name =
let metadata: serde_json::Value = match serde_json::from_str(&metadata_str) {
Ok(value) => value,
Err(e) => {
warn!("Failed to parse metadata JSON: {}", e);
return (String::new(), None, None, None, String::new());
}
};
let metadata_name =

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Project coverage is 55.50%. Comparing base (0cb5923) to head (a2fe03e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ates/torii/graphql/src/object/erc/token_balance.rs 0.00% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2764      +/-   ##
==========================================
- Coverage   55.50%   55.50%   -0.01%     
==========================================
  Files         434      434              
  Lines       54295    54307      +12     
==========================================
+ Hits        30137    30141       +4     
- Misses      24158    24166       +8     

☔ 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: 1

🧹 Outside diff range and nitpick comments (1)
.github/workflows/preview.yml (1)

Line range hint 1-77: Ohayo sensei! Here are some workflow optimization suggestions.

  1. Consider consolidating the two cache actions into one by using a pattern:
path: /tmp/.buildx-cache/*
  1. Consider using a more efficient cache key strategy:
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
  1. Define the platform as an environment variable to avoid duplication.

Would you like me to provide a complete optimized version of the workflow?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dd8238a and 54a2c73.

📒 Files selected for processing (1)
  • .github/workflows/preview.yml (1 hunks)

mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild
rm -rf /tmp/.buildx-cache/build
mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Critical cache management issue detected.

The workflow writes Docker cache to new locations (/tmp/.buildx-cache-new/*) but never moves them to the expected cache locations (/tmp/.buildx-cache/*). This will prevent cache from being restored in subsequent runs, defeating the purpose of caching and significantly increasing build times.

Please add the following steps after each build step:

      - name: Move prebuild cache
        run: |
          rm -rf /tmp/.buildx-cache/prebuild
          mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild

      - name: Move build cache
        run: |
          rm -rf /tmp/.buildx-cache/build
          mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build

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

🧹 Outside diff range and nitpick comments (1)
.github/workflows/preview.yml (1)

86-86: Add newline at end of file.

 mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build || true
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 86-86: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 54a2c73 and 7dbbd9c.

📒 Files selected for processing (1)
  • .github/workflows/preview.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/preview.yml

[error] 86-86: no new line character at the end of file

(new-line-at-end-of-file)

@@ -81,6 +81,6 @@ jobs:
name: Move cache
run: |
rm -rf /tmp/.buildx-cache/prebuild
mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild
mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild || true
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo sensei! Consider improving error handling for cache operations.

While adding || true prevents workflow failures, it silently ignores potential cache issues. Consider adding error logging:

- mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild || true
- mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build || true
+ mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild || echo "Warning: Failed to move prebuild cache"
+ mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build || echo "Warning: Failed to move build cache"

Also applies to: 86-86

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.

1 participant