refactor: optimize source fetching by introducing caching for AspenOn… - #487
Open
asmfstatoil wants to merge 1 commit into
Open
asmfstatoil wants to merge 1 commit into
asmfstatoil wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The caches can mix TLS policies, retain failed responses, expose mutable results, and are bypassed by the public PI path.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
Open (7)
Cache key omits TLS trust configuration · New Cache key omits TLS trust configuration · New Malformed JSON is cached as an empty source list · New Return a copy to prevent cache mutation · New Default public calls bypass the source cache · New Malformed JSON is cached as an empty source list · New Return a copy to prevent cache mutation · New
What changed in this PR
Adds source-list caching for AspenOne and PI Web API to reduce repeated network requests.
Changes:
- Extracts source fetching into private helpers.
- Caches default-auth results by URL.
- Bypasses caching for explicit authentication.
| File | Description |
|---|---|
| tagreader/web_handlers.py | Adds source-fetch helpers and caches for AspenOne and PI Web API. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+114
to
+115
| # Keyed on url only so default-auth calls share the cache regardless of auth or verify_ssl. | ||
| _aspenone_sources_cache: Dict[str, List[str]] = {} |
Comment on lines
+160
to
+161
| # Keyed on url only so default-auth calls share the cache regardless of auth or verify_ssl. | ||
| _piwebapi_sources_cache: Dict[str, List[str]] = {} |
Comment on lines
+129
to
+132
| if url not in _aspenone_sources_cache: | ||
| _aspenone_sources_cache[url] = _fetch_aspenone_sources( | ||
| url, get_auth_aspen(), verify_ssl | ||
| ) |
| _aspenone_sources_cache[url] = _fetch_aspenone_sources( | ||
| url, get_auth_aspen(), verify_ssl | ||
| ) | ||
| return _aspenone_sources_cache[url] |
Comment on lines
+172
to
+173
| if auth is not None: | ||
| return _fetch_piwebapi_sources(url, auth, verify_ssl) |
Comment on lines
+175
to
+178
| if url not in _piwebapi_sources_cache: | ||
| _piwebapi_sources_cache[url] = _fetch_piwebapi_sources( | ||
| url, get_auth_pi(), verify_ssl | ||
| ) |
| _piwebapi_sources_cache[url] = _fetch_piwebapi_sources( | ||
| url, get_auth_pi(), verify_ssl | ||
| ) | ||
| return _piwebapi_sources_cache[url] |
This branch has not been deployed
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.


…e and PI Web API