Regularly refresh materialized view view from indexer#1013
Merged
Conversation
0xaslan
reviewed
May 14, 2026
|
|
||
| /// Query net deposits using the materialized view for efficiency. | ||
| /// Triggers a concurrent refresh of the view and queries for net deposits up to timestamp. | ||
| /// The indexer refreshes this view with a write-capable database connection. |
Collaborator
There was a problem hiding this comment.
Moving REFRESH MATERIALIZED VIEW off the API reader path is the right direction for readonly DBs, but this query still assumes the view is fresh for every bucket before hour_bucket_ms. With a 30s async indexer refresh, a request just after an hour boundary, or during refresh failures, can miss late writes from the previous completed hour: they are not in the MV yet, and the raw balances scan starts at the new hour. To keep the reader readonly and exact, the writer/indexer refresh path should publish a refresh watermark, and this query should use the MV only before that watermark while scanning raw balances from the watermark to timestamp_ms.
0xaslan
approved these changes
May 14, 2026
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.
Summary
MATERIALIZED_VIEWS_TO_REFRESHregistry. The current registry refreshesnet_deposits_hourly.materialized_view_refresh_successes_total{view="..."},materialized_view_refresh_failures_total{view="..."}, andmaterialized_view_refresh_duration_seconds{view="..."}.Key decisions
balancesfrom the cutoff to the requested timestamp.Test plan