Skip to content

refactor: optimize source fetching by introducing caching for AspenOn… - #487

Open
asmfstatoil wants to merge 1 commit into
mainfrom
cache_sources
Open

asmfstatoil wants to merge 1 commit into
mainfrom
cache_sources

Conversation

@asmfstatoil

Copy link
Copy Markdown
Collaborator

…e and PI Web API

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 5 Medium severity

Open (7)
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 thread tagreader/web_handlers.py
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 thread tagreader/web_handlers.py
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 thread tagreader/web_handlers.py
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
)
Comment thread tagreader/web_handlers.py
_aspenone_sources_cache[url] = _fetch_aspenone_sources(
url, get_auth_aspen(), verify_ssl
)
return _aspenone_sources_cache[url]
Comment thread tagreader/web_handlers.py
Comment on lines +172 to +173
if auth is not None:
return _fetch_piwebapi_sources(url, auth, verify_ssl)
Comment thread tagreader/web_handlers.py
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
)
Comment thread tagreader/web_handlers.py
_piwebapi_sources_cache[url] = _fetch_piwebapi_sources(
url, get_auth_pi(), verify_ssl
)
return _piwebapi_sources_cache[url]

This branch has not been deployed

No deployments
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.

2 participants