-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize balance-related queries with a cache (#2383)
## Linked Issues/PRs Closes #1965 ## Description 1. The client uses the off-chain database metadata to tell if it can use the optimized queries or fall-back to the legacy ones. 2. When client starts the metadata is either: 1. Kept intact in-case genesis exists (meaning - no optimized queries are available) * this stems from the fact that the pre-existing DB contains some coins already and we'll **not** be re-indexing them in order to create the lookup indexes * in this mode of operation the "old" way of getting balances is used as confirmed in logs: * `worker_service: 607: Balances cache available: false` * `query::balance: 100: Querying balances without balances cache owner=53a9c6a...` 2. Initialized with `V2` if genesis is missing * this means that while re-syncing the DB the balance indexes are going to be created and could be used to satisfy the requests * `worker_service: 607: Balances cache available: true` * `query::balance: 151: Querying balances using balances cache owner=53a9c6a...` Technical considerations: * Metadata is extended with `V2` which now contains `indexation_availability`. This is a set that holds the available indexations (currently only `Balances`) * New databases are added: `CoinBalances` and `MessageBalances` that keep the coin and message balances respectively * `CoinBalances` stores the balances per `owner` and `asset_id` * `MessageBalances` stores balances per `owner`, separately for retryable and non-retryable messages * In case balances indexation is available (see "Description" above): * these databases are updated in the GrapQL API worker service when processing one of these events: `MessageImported`, `MessageConsumed`, `CoinCreated`, `CoinConsumed` * `balance()` and `balances()` queries use these databases to satisfy the query ## Checklist - [X] New behavior is reflected in tests ### Before requesting review - [X] I have reviewed the code myself --------- Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
- Loading branch information
Showing
34 changed files
with
1,484 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.