Speed up queries via materialized view#1671
Conversation
Flix6x
left a comment
There was a problem hiding this comment.
Some early review comments. Nice to see the refresh logic taking shape.
Documentation build overview
Show files changed (5 files in total): 📝 5 modified | ➕ 0 added | ➖ 0 deleted
|
Flix6x
left a comment
There was a problem hiding this comment.
Exciting work! Thanks for addressing my earlier comments. Just a short code review for now, so you don't have to wait for me testing. Looking forward to testing tomorrow.
nhoening
left a comment
There was a problem hiding this comment.
Also a quick review from me, before having tested myself, mostly about concepts.
I also suggest moving get_timed_belief_min_v() to timely-beliefs and add basic documentation there (not much more than the SQL command so anybody reading only that could in principle use it)
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Signed-off-by: Muhammad-Moiz626 <muhammadmoiz4843@gmail.com>
…erialized-veiws # Conflicts: # documentation/changelog.rst # documentation/configuration.rst # flexmeasures/data/models/generic_assets.py # flexmeasures/ui/templates/base.html
Signed-off-by: F.N. Claessen <felix@seita.nl>
Resolved conflicts in changelog.rst, configuration.rst, time_series.py, assets.py, base.html, and views.py, keeping materialized view features alongside upstream changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
base.html gained ~950 lines of stale template blocks (copies of JS that lives in includes/graphs.html) and openapi-specs.json had its version reverted. Restore both to main; the materialized-view UI toggle will be re-added on top of the real chart-loading code in includes/graphs.html. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qprz6PKnXkVE1TJ8d7PYe9
# Conflicts: # documentation/changelog.rst
…recorded refresh time - migration: frozen SQL from timely-beliefs' DDL generators (simplified view query, no CASCADE on downgrade), repointed onto main's migration head (drops the stale merge migration) - CLI: refresh-materialized-views records its run in latest_task_run via @task_with_status_report, supports --concurrent (autocommit connection), aborts with an error exit code on failure; monitorable with 'flexmeasures monitor latest-run' - config: replace FLEXMEASURES_MVIEW_REFRESH_INTERVAL with FLEXMEASURES_MVIEW_ALWAYS_INCLUDE_LIVE_TAIL (the refresh cadence now lives solely in how hosts schedule the CLI command; the recorded refresh time is the single source of truth) - queries: TimedBelief.search decides centrally whether to trust the view (it must exist at startup and have a recent enough recorded refresh) and passes a cutoff so events recorded since the last refresh are looked up in the beliefs table (live tail); new include_live_tail param threaded through Sensor/GenericAsset.search_beliefs and the chart data API endpoints - UI: 'Include latest data' toggle on asset graphs (shown only when the view is in use and the live tail is not already always included), wired to the real chart-loading code in includes/graphs.html; tooltip shows the actual last refresh time - docs: configuration.rst setting description, hosting docs section with cron example, changelog entry - tests: CLI refresh success/failure recording, mview/live search equivalence Note: requires the timely-beliefs release containing SeitaBV/timely-beliefs#204 (materialized_views module); the dependency pin should be bumped once that is released. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qprz6PKnXkVE1TJ8d7PYe9
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…at/materialized-veiws # Conflicts: # uv.lock
Description
Our data model with multiple beliefs per event time (multiple horizons as well as sources) makes queries computationally expensive. Most-used are queries where we look only for the most recent beliefs about each event, when given any moment in time as max belief time.
Pre-computation with Postgres' materialized views can make queries much faster. This PR will enable hosts to use this performance enhancement.
...
Further Improvements
Related Items
Closes 108
...
Sign-off