Skip to content

Optimize dashboard history queries and cache lifetimes - #30

Merged
mot-yelraf merged 1 commit into
trunkfrom
dashboard-optimization
Sep 19, 2026
Merged

mot-yelraf merged 1 commit into
trunkfrom
dashboard-optimization

Conversation

@mot-yelraf

@mot-yelraf mot-yelraf commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

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

  • macOS, Python 3.13.9: focused database, statistics, compilation, and dashboard route checks passed (68 checks).
  • 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.
  • Read-only SQL comparisons used a Raspberry Pi 5 running Debian 13.6; no service deployment or database changes were performed.
  • User verified the changes before requesting this PR workflow.

Contributor checklist

  • This pull request is focused on one logical change.
  • I added or updated tests for behavior changes.
  • I updated the canonical documentation when behavior or configuration changed.
  • I did not commit credentials, private runtime configuration, databases, or logs.
  • I preserved compatibility-sensitive MQTT, settings, switch identity, and persistence behavior, or documented an intentional break.

Maintainer verification

  • Required remote checks pass (Python 3.11/3.13 compilation and the full regression suite with coverage floor).
  • npm run validate:pr passes on a trusted host when the change can affect rendered UI behavior.
  • Hardware-, broker-, onboarding-, and platform-specific behavior not covered remotely is recorded below.

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.

@mot-yelraf
mot-yelraf merged commit 88313d0 into trunk Sep 19, 2026
3 checks passed
@mot-yelraf
mot-yelraf deleted the dashboard-optimization branch September 19, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant