Optimize dashboard history queries and cache lifetimes - #30
Merged
Merged
Conversation
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
Dashboard requests on hub 3 took about nine seconds because several queries scanned or sorted historical readings. Use existing indexes for recent trends and latest packets, sort only distinct sensor IDs, and check the JSON cache before database work. Cache lifetimes now begin after computation finishes. Preserve case-sensitive historical identities and complete packets with tied timestamps; no schema migration is needed.
Read-only comparisons of the exact branch SQL against hub 3 returned identical rows: trends improved from 3.873 to 0.123 seconds, latest packets from 1.458 to 0.0005 seconds, and sensor inventory from 2.261 to 0.459 seconds. Update operations documentation and version to
v0.26.262.2.Verification
python3 -m pytest -q testApparatus/test_compile_python.py testApparatus/test_dashboard_query_optimization.py testApparatus/test_sai_stats_trends.py testApparatus/test_datalogger_migration.py testApparatus/test_fast_stats.py: 31 passed.python3 -m pytest -q testApparatus/test_nodus_settings_schema_writes.py -k 'dashboard or companion_return': 37 passed.npm run validate:pr: all 42 Chromium checks passed on the isolated macOS fixture host.Contributor checklist
Maintainer verification
npm run validate:prpasses on a trusted host when the change can affect rendered UI behavior.Residual risk or unverified areas
End-to-end dashboard latency after deployment has not been measured. Tests used isolated host fixtures without a live MQTT broker or GPIO hardware; onboarding and live hardware behavior were not exercised. The SQL benchmark measures individual queries, not complete requests under concurrent load.