Skip to content

fix(x): optimize gprc queries for collection use#2046

Merged
troian merged 1 commit intomainfrom
grpc-queries
Mar 4, 2026
Merged

fix(x): optimize gprc queries for collection use#2046
troian merged 1 commit intomainfrom
grpc-queries

Conversation

@troian
Copy link
Member

@troian troian commented Mar 4, 2026

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Signed-off-by: Artur Troian <troian@users.noreply.github.com>
@troian troian requested a review from a team as a code owner March 4, 2026 19:02
@troian troian merged commit a945973 into main Mar 4, 2026
31 checks passed
@troian troian deleted the grpc-queries branch March 4, 2026 19:02
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ab6c8504-070a-428f-b936-7674aacdaecf

📥 Commits

Reviewing files that changed from the base of the PR and between 1d36cc1 and b4c3592.

📒 Files selected for processing (2)
  • x/deployment/keeper/grpc_query.go
  • x/market/keeper/grpc_query.go

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

Two keeper modules refactor their gRPC query handlers to support multi-path traversal strategies for list operations. Deployment queries now route through direct-get, owner-path, or state-index paths with conditional logic based on provided filters. Similarly, Orders, Bids, and Leases queries adopt branching path resolution with distinct helpers for direct-get, owner-prefix, provider-index, and state-index traversals, maintaining consistent pagination and state filtering across paths.

Changes

Cohort / File(s) Summary
Deployment Query Path Resolution
x/deployment/keeper/grpc_query.go
Introduces multi-path query routing with direct-get (when Owner and DSeq provided), owner-path iteration (deploymentsOwnerPath), and state-index path (deploymentsStatePath). Replaces hardcoded state handling with conditional INITIAL phase supporting default Active/Closed states or user-specified state filters. Adds escrow account and group lookups per deployment with pagination-aware key encoding.
Market Query Path Resolution
x/market/keeper/grpc_query.go
Refactors Orders, Bids, and Leases queries into distinct path-based handlers: direct-get (full primary keys), owner-prefix/owner-based iteration, provider-index path (for Bids/Leases), and state-index path. Introduces new helper methods per entity type (ordersDirectGet, ordersOwnerPath, ordersStatePath; bidsOwnerPath, bidsProviderPath, bidsStatePath; leasesOwnerPath, leasesProviderPath, leasesStatePath) with consistent state filtering, pagination, and escrow/payment data retrieval. Adds error and market/v1 imports for enhanced error handling and type resolution.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant QueryHandler
    participant PathResolver
    participant KVStore
    participant EscrowService
    
    Client->>QueryHandler: Query request (filters, pagination)
    QueryHandler->>PathResolver: Determine execution path<br/>(direct-get, owner-path, provider-path, state-index)
    alt Direct-Get Path
        PathResolver->>KVStore: Fetch single entity by primary keys
    else Owner-Path
        PathResolver->>KVStore: Iterate by owner prefix
    else Provider-Path
        PathResolver->>KVStore: Iterate by provider index
    else State-Index Path
        PathResolver->>KVStore: Iterate by state index
    end
    PathResolver->>KVStore: Apply state filter & pagination offset/limit
    loop For Each Result Item
        KVStore->>EscrowService: Fetch related escrow account/payment
        EscrowService-->>KVStore: Return escrow data
    end
    PathResolver->>QueryHandler: Encode next pagination key
    QueryHandler-->>Client: Return paginated results with next-key
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 Query paths diverge in queries deep,
Where direct-get and owner-paths leap,
Through states and pagination we bound,
Escrow and groups are safely found,
Multi-path routing, a refactor so neat!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch grpc-queries

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant