Skip to content

Fix orders and vaults list queries#2200

Merged
hardyjosh merged 1 commit intomainfrom
routing-fix
Oct 13, 2025
Merged

Fix orders and vaults list queries#2200
hardyjosh merged 1 commit intomainfrom
routing-fix

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Oct 13, 2025

Motivation

When the webapp sent an empty list for the selected chain ids, the queries were not hitting the sg or local db branches. If that is the case we are defaulting to sg

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Refactor
    • Streamlined order and vault retrieval when no IDs are provided, directly querying the remote source and skipping unnecessary local lookups.
    • Reduces latency and resource usage for broad queries, improving responsiveness.
    • No changes to public interfaces or expected behavior.

@findolor findolor requested review from 0xgleb and hardyjosh October 13, 2025 14:33
@findolor findolor self-assigned this Oct 13, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 13, 2025

Walkthrough

Adds early-return branches in RaindexClient get_orders and get_vaults: when both local_ids and sg_ids are empty, the functions directly call their respective subgraph fetchers (get_orders_sg / get_vaults_sg) with None and return, bypassing local DB/partitioning logic. No public APIs or signatures changed.

Changes

Cohort / File(s) Summary
RaindexClient empty-ID short-circuit
crates/common/src/raindex_client/orders.rs, crates/common/src/raindex_client/vaults.rs
Introduce early return when both local_ids and sg_ids are empty, delegating to get_orders_sg(None, ...) / get_vaults_sg(None, ...); otherwise preserve existing local-db vs SG partitioning and aggregation flow.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as RaindexClient
  participant L as Local DB
  participant SG as Subgraph

  rect rgb(235,245,255)
  note over C: get_orders(...)
  alt No local_ids and no sg_ids
    C->>SG: get_orders_sg(None, filters, page)
    SG-->>C: Orders
  else IDs provided
    C->>L: Fetch local orders (subset)
    L-->>C: Local orders
    C->>SG: get_orders_sg(Some(ids), filters, page)
    SG-->>C: SG orders
    C-->>C: Aggregate and return
  end
  end
Loading
sequenceDiagram
  autonumber
  participant C as RaindexClient
  participant L as Local DB
  participant SG as Subgraph

  rect rgb(235,245,255)
  note over C: get_vaults(...)
  alt No local_ids and no sg_ids
    C->>SG: get_vaults_sg(None, filters, page)
    SG-->>C: Vaults
  else IDs provided
    C->>L: Fetch local vaults (subset)
    L-->>C: Local vaults
    C->>SG: get_vaults_sg(Some(ids), filters, page)
    SG-->>C: SG vaults
    C-->>C: Aggregate and return
  end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • hardyjosh
  • 0xgleb

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change by indicating that the list queries for both orders and vaults have been fixed, which directly aligns with the added short-circuit logic in the get_orders and get_vaults functions. It is specific enough to convey the intent of the changes without unnecessary detail or ambiguity. The phrasing is concise, making it easy for a teammate to understand the main purpose of the pull request at a glance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch routing-fix

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 725b860 and 41760df.

📒 Files selected for processing (2)
  • crates/common/src/raindex_client/orders.rs (1 hunks)
  • crates/common/src/raindex_client/vaults.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
crates/*/{src,tests,benches,examples}/**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Rust code must pass clippy with all warnings denied (cargo clippy --workspace --all-targets --all-features -D warnings)

Files:

  • crates/common/src/raindex_client/orders.rs
  • crates/common/src/raindex_client/vaults.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Files:

  • crates/common/src/raindex_client/orders.rs
  • crates/common/src/raindex_client/vaults.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Format Rust with nix develop -c cargo fmt --all
Lint Rust with nix develop -c rainix-rs-static (preconfigured flags)
Use snake_case for Rust crates/modules and PascalCase for types

Files:

  • crates/common/src/raindex_client/orders.rs
  • crates/common/src/raindex_client/vaults.rs
🧠 Learnings (1)
📚 Learning: 2025-10-02T19:17:20.332Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2163
File: crates/common/src/raindex_client/orders.rs:738-741
Timestamp: 2025-10-02T19:17:20.332Z
Learning: In crates/common/src/raindex_client/orders.rs, fetch_dotrain_source() is intentionally called in try_from_sg_order for every order conversion because the dotrain source information is needed immediately. A future optimization with local DB logic is planned to eliminate the network round-trip concern.

Applied to files:

  • crates/common/src/raindex_client/orders.rs
🧬 Code graph analysis (1)
crates/common/src/raindex_client/vaults.rs (1)
crates/common/src/raindex_client/vaults_list.rs (1)
  • new (18-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: Deploy-Docs-Preview

Comment on lines +519 to +521
if local_ids.is_empty() && sg_ids.is_empty() {
return self.get_orders_sg(None, filters, page).await;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

❓ Verification inconclusive

Clarify the intended behavior for empty chain IDs and add test coverage.

The early-return when both local_ids and sg_ids are empty now treats Some(ChainIds(vec![])) semantically equivalent to None—both query all configured networks. While this aligns with the PR's stated goal of defaulting to SG when the webapp sends an empty list, consider:

  1. Semantic Clarity: An empty list could reasonably mean "query nothing" (return empty results). If "query all" is the intended behavior for empty lists, document this in the function's docstring or add an inline comment explaining why Some(empty) is treated as None.

  2. Test Coverage: Add a test case that explicitly passes Some(ChainIds(vec![])) and verifies it queries all networks (or returns expected results), ensuring this edge case is maintained in future refactors.


🏁 Script executed:

#!/bin/bash
# Description: Verify if there are existing tests for empty ChainIds
# Expected: Should find tests or confirm none exist

rg -n -A3 -B3 'ChainIds\(vec!\[\]\)' --type rust

Length of output: 0


Document empty chain IDs behavior and add missing test

  • Clarify in the function’s docstring or an inline comment why Some(ChainIds(vec![])) is treated the same as None (query all networks).
  • Add a test that passes Some(ChainIds(vec![])) and verifies it queries all configured networks.
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/orders.rs around lines 519 to 521, document
why passing Some(ChainIds(vec![])) is treated as equivalent to None (i.e., it
means "query all configured networks") by adding a concise docstring or inline
comment above the function explaining that an empty ChainIds vector is
interpreted as a wildcard for all networks; then add a unit/integration test
that calls the function with Some(ChainIds(vec![])) and asserts it produces the
same query/behavior as calling it with None (verifying it queries all configured
networks), placing the test in the existing orders tests module or the
appropriate test file for raindex_client/orders.

Comment on lines +1110 to +1113
if local_ids.is_empty() && sg_ids.is_empty() {
let vaults = self.get_vaults_sg(None, filters, page).await?;
return Ok(RaindexVaultsList::new(vaults));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Consistent implementation with orders.rs—same clarification needed.

This early-return mirrors the pattern introduced in get_orders (orders.rs:519-521), maintaining consistency across both functions. The same concerns apply here:

  • Semantic Equivalence: Some(ChainIds(vec![])) is now treated as None, both querying all configured networks.
  • Documentation: Consider adding a comment explaining this behavior.
  • Test Coverage: Ensure tests verify this edge case for vaults as well.

See the review comment on orders.rs:519-521 for additional context.

@hardyjosh hardyjosh enabled auto-merge October 13, 2025 14:48
@hardyjosh hardyjosh merged commit 5574275 into main Oct 13, 2025
19 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 13, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the diff statistics for the entire PR
gh pr view 2200 --repo rainlanguage/rain.orderbook --json additions,deletions,changedFiles | jq -r '"ADDITIONS=\(.additions) DELETIONS=\(.deletions) FILES=\(.changedFiles)"'

# Get the actual diff to review the changes
gh pr diff 2200 --repo rainlanguage/rain.orderbook

Length of output: 1280


SIZE=S


🧠 Learnings used
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:42.275Z
Learning: For PR #1884, after each commit review, I should provide a new comment with a PR size report in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding irrelevant files such as lock files (package-lock.json, cargo.lock, etc.).

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.

3 participants