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

feat(sdk): fetch many and return metadata and proof to client #2331

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Nov 15, 2024

Issue being fixed or feature implemented

Clients sometimes want to see the metadata or the proof data, this was implemented for fetch, but was not implemented for fetch_many.

What was done?

Returns metadata and proof for fetch_many

How Has This Been Tested?

Not tested

Breaking Changes

No breaking changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced new asynchronous methods in the FetchMany trait for enhanced data retrieval, including fetching with metadata and proof.
    • Updated the existing fetch_many method to return additional metadata alongside the fetched objects.
  • Bug Fixes

    • Improved error handling and response parsing in the fetch_many method to accommodate new features.
  • Refactor

    • Simplified the equality comparison behavior of the ExecutionResponse struct.

@QuantumExplorer QuantumExplorer added enhancement New feature or request rs-sdk labels Nov 15, 2024
@QuantumExplorer QuantumExplorer added this to the v1.6.0 milestone Nov 15, 2024
@QuantumExplorer QuantumExplorer self-assigned this Nov 15, 2024
Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes involve modifications to two files: executor.rs and fetch_many.rs. In executor.rs, the ExecutionResponse struct has been updated by removing the Eq trait from its derived attributes, affecting its equality comparison capabilities. In fetch_many.rs, the FetchMany trait has been enhanced with three new asynchronous methods for fetching data with metadata and proofs, alongside modifications to the existing fetch_many method to accommodate these new features.

Changes

File Change Summary
packages/rs-dapi-client/src/executor.rs Removed Eq from #[derive(Debug, Clone, Eq, PartialEq)] for ExecutionResponse<R>.
packages/rs-sdk/src/platform/fetch_many.rs Added methods: fetch_many_with_metadata, fetch_many_with_metadata_and_proof. Updated fetch_many to call the new method and modified its internal logic.

Suggested reviewers

  • shumkov

Poem

In the code where bunnies play,
Traits and methods find their way.
With metadata now in tow,
Fetching data starts to glow!
Equality's a simpler dance,
In this code, we take our chance! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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.

lklimek
lklimek previously approved these changes Nov 15, 2024
Copy link
Contributor

@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)
packages/rs-sdk/src/platform/fetch_many.rs (2)

235-236: Avoid unnecessary cloning of request

In the fetch_many_with_metadata_and_proof method, request.clone() is used when calling parse_proof_with_metadata_and_proof. If possible, consider passing a reference to request instead of cloning to improve performance and reduce overhead.


Line range hint 336-366: Refactor fetch_many implementation for Document to use base method

In the implementation of FetchMany<Identifier, Documents> for Document, the fetch_many method is re-implemented separately and does not utilize fetch_many_with_metadata_and_proof, unlike the base trait. To maintain consistency and reduce code duplication, consider refactoring this method to call the base fetch_many implementation or modify it to use fetch_many_with_metadata_and_proof.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f1f0470 and 0668f4f.

📒 Files selected for processing (2)
  • packages/rs-dapi-client/src/executor.rs (1 hunks)
  • packages/rs-sdk/src/platform/fetch_many.rs (4 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/rs-dapi-client/src/executor.rs (1)
Learnt from: lklimek
PR: dashpay/platform#2277
File: packages/rs-dapi-client/src/executor.rs:38-38
Timestamp: 2024-11-12T14:57:47.419Z
Learning: In `packages/rs-dapi-client/src/executor.rs`, for the structs `ExecutionError<E>` and `ExecutionResponse<R>`, only the serde derives (`Serialize`, `Deserialize`) should be conditional based on the "mocks" feature; the other derives (`Debug`, `Clone`, `Eq`, `PartialEq`) should always be present.
🔇 Additional comments (2)
packages/rs-dapi-client/src/executor.rs (1)

79-79: Verify the impact of removing the Eq trait.

The removal of the Eq trait could be a breaking change if any code relies on full equality comparison of ExecutionResponse. This needs verification as the PR objectives state "no breaking changes".

✅ Verification successful

Removing Eq trait is safe in this context

The verification shows that ExecutionResponse is only used for equality comparison in test code (mock_dapi_client.rs), where PartialEq is sufficient. The struct is primarily used for returning responses from API calls, and there's no evidence of it being used in contexts requiring full equality (like HashSet or BTreeSet). The removal of Eq is not a breaking change as PartialEq satisfies all current usage patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential usage of equality comparison on ExecutionResponse

# Look for direct equality comparisons
rg -A 2 "ExecutionResponse.*==|assert.*ExecutionResponse"

# Look for trait bounds requiring Eq
ast-grep --pattern 'where $type: Eq'

# Look for derive(Eq) on types containing ExecutionResponse
ast-grep --pattern '#[derive($$$Eq$$$)]
struct $name {
  $$$
  $field: ExecutionResponse<$type>,
  $$$
}'

Length of output: 206


Script:

#!/bin/bash
# Let's try a broader search to understand the usage of ExecutionResponse

# Find all files containing ExecutionResponse
rg --type rust "ExecutionResponse" -l

# Look for any comparisons or assertions in test files
rg --type rust -g "*test*.rs" "ExecutionResponse"

# Look for any collections (HashSet, BTreeSet) that might require Eq
rg --type rust "ExecutionResponse.*HashSet|ExecutionResponse.*BTreeSet"

# Look for the struct definition and its usage
ast-grep --pattern 'struct ExecutionResponse'

Length of output: 573


Script:

#!/bin/bash
# Let's examine how ExecutionResponse is used in the codebase

# Look at the struct definition and its usage context
rg -B 3 -A 10 "struct ExecutionResponse" packages/rs-dapi-client/src/executor.rs

# Check if it's used in any function signatures or return types
ast-grep --pattern 'fn $name($$$) -> $ret<ExecutionResponse<$type>>'

# Look for any pattern matching or destructuring
rg --type rust "match.*ExecutionResponse|if let.*ExecutionResponse"

# Check test files specifically for the struct usage
cat packages/rs-dapi-client/tests/mock_dapi_client.rs

Length of output: 2209

packages/rs-sdk/src/platform/fetch_many.rs (1)

149-152: Refactored fetch_many to delegate to fetch_many_with_metadata_and_proof

The fetch_many method now correctly calls fetch_many_with_metadata_and_proof, enhancing code reuse and maintaining consistency across methods.

packages/rs-dapi-client/src/executor.rs Outdated Show resolved Hide resolved
retries,
})
.map(|(o, metadata, proof)| ExecutionResponse {
inner: (o.unwrap_or_default(), metadata, proof),
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 15, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle potential None value without using unwrap_or_default()

On line 245, o.unwrap_or_default() is used when constructing the ExecutionResponse. This could mask situations where no data is returned (o is None), possibly leading to confusion for the caller. Consider handling the None case explicitly, perhaps by returning an error or conveying that no data was found.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's okay

Copy link
Contributor

Choose a reason for hiding this comment

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

@QuantumExplorer, understood.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@QuantumExplorer QuantumExplorer merged commit b81f895 into v1.6-dev Nov 15, 2024
24 of 25 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/fetchManyWithMetadataAndProof branch November 15, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rs-sdk
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants