perf(cli): read a single on-chain issue by ID instead of scanning all#1390
Open
kinjitakabe wants to merge 1 commit into
Open
perf(cli): read a single on-chain issue by ID instead of scanning all#1390kinjitakabe wants to merge 1 commit into
kinjitakabe wants to merge 1 commit into
Conversation
fetch_issue_from_contract resolved one issue by reading every issue on the contract (one childstate RPC per issue, growing with next_issue_id). Add read_issue_from_contract to fetch a single issue via its computed lazy key in one RPC, and route fetch_issue_from_contract through it. The per-issue decode is shared via _read_one_issue_from_child_storage so the full-scan and single-read paths don't duplicate it.
Collaborator
|
fix conflicts |
Collaborator
|
Fix conflicts. Heads up: test now distinguishes a contract read error (ClickException "Error reading from contract: …") from a genuine not-found in fetch_issue_from_contract. read_issue_from_contract here swallows exceptions and returns None, which would report connection failures as "Issue ID N not found on-chain." Preserve that distinction when you rebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this is necessary:
fetch_issue_from_contractis used to act on one issue by ID (e.g.gitt issues submissions --id <N>), but it currently reads every issue registered on the contract to find it:That's O(N) substrate RPC round-trips to fetch O(1) data.
next_issue_idonly ever grows — completed and cancelled issues are never removed from storage — so every single-issue command gets progressively slower and pounds the node with N round-trips for data whose storage key it can compute directly. The Ink! 5 lazy mapping key for a specificissue_idis already computable inline, so a single read was always possible; the code just wasn't using it.The fix: add
read_issue_from_contract, which computes the one issue's lazy key and does a singlechildstate_getStoragecall, and routefetch_issue_from_contractthrough it. O(N) → O(1).The per-issue decode is factored into a shared
_read_one_issue_from_child_storagehelper, so the full-scan path (read_issues_from_contract, used byissues list) and the new single-read path share one decode implementation instead of duplicating it. Behavior is unchanged:fetch_issue_from_contractstill raises the sameClickExceptions for not-found, non-bountied, and incomplete issues.Related Issues
N/A
Type of Change
Testing
tests/cli/test_issue_single_read.py: single read does exactly one RPC,returns
Nonewhen absent,fetch_issue_from_contractuses the single read(asserts the full scan is not called), and the not-found / non-bountied
paths still raise
ClickException.uv run pytest— 882 passed.uv run pyright/ruff check/vultureon changed files — clean.Checklist