Repository navigation
Read the resource tree only once and cache it - #22
Merged
Merged
Conversation
The /api/v1/var resource tree only changes when the myGEKKO configuration is changed, but it was fetched on every read_data() call together with /api/v1/var/status. Fetching it once and caching it halves the number of requests per polling cycle and avoids transferring the largest API response over and over. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Xitee1
marked this pull request as draft
July 15, 2026 07:15
StephanU
approved these changes
Aug 5, 2026
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the resource-tree caching change.
No open issues 🎉
What changed in this PR
Caches the myGEKKO resource tree in DataProvider to reduce polling requests and data transfer while continuing to refresh status on every cycle.
Changes:
- Fetches
/api/v1/varonly whileresourcesisNone, preserving retries after an initial fetch or JSON parsing failure. - Adds a regression test verifying one resource-tree request and two status requests across two polling calls.
| File | Description |
|---|---|
tests/test_pymygekko.py |
Tests resource caching and continued status polling. |
PyMyGekko/data_provider.py |
Reuses the cached resource tree on subsequent reads. |
Review effort: Balanced
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.
What
DataProvider.read_data()fetched both/api/v1/var(the full resource tree) and/api/v1/var/statuson every call. The resource tree is the largest response the Query API produces and only changes when the myGEKKO configuration itself is changed, so this PR fetches it only on the firstread_data()call and caches it afterwards. Every subsequent cycle only requests/api/v1/var/status.Why
Notes
resourcesstaysNoneand the nextread_data()call retries it, matching the previous behavior./api/v1/varis requested once across tworead_data()calls while/api/v1/var/statusis requested each time.🤖 Generated with Claude Code