CodeChain-io / CodeChain-io/codechain-indexer

Remove O(m) DB queries

Open
#316 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21
Forks
15
PR merge metrics
No merged PRs in 30d

Description

When querying UTXOs using Asset type, aggregating UTXOs by account, and creating a snapshot, the Indexer scans all the UTXOs that have a specific account or a specific asset type.

When a user opens a CodeChain web wallet, wallet requests the total amount of assets that the user has to the Indexer. Indexer sends a query that scans all the UTXOs that the user has. If the number of UTXOs that the user has is `m`, the upper bound of the query is `O(m)`.

### How to solve

Make APIs return sub results that read k rows in the DB. The Web wallet or Hub should request the maximum `[n/k]` number of API calls to get all the results. The upper bound of each query is O(k*log m). Then there won't be a single slow query that consumes all the resources(CPU, Memory, disk I/O) in the DB.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the Indexer entry points for Asset-type UTXO queries, account aggregation, snapshot creation, and the APIs used by the web wallet or Hub. Review how these queries currently scan results and determine the API and consumer changes needed so results are fetched in bounded batches; done means no single request scans all m UTXOs.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, databases, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.