Skip to content

Refactor: extract _image_cache_key helper and drop stale response_model on get_nearby_issues#587

Draft
Copilot wants to merge 2 commits intobolt-optimization-cache-serialization-14526281583048350032from
copilot/sub-pr-573
Draft

Refactor: extract _image_cache_key helper and drop stale response_model on get_nearby_issues#587
Copilot wants to merge 2 commits intobolt-optimization-cache-serialization-14526281583048350032from
copilot/sub-pr-573

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

Description

Addresses two review comments from PR #573: eliminates duplicated MD5 cache-key construction in detection.py and removes a misleading response_model annotation that diverged from the actual raw-Response return type.

Changes

  • backend/routers/detection.py: Extracted _image_cache_key(prefix, image_bytes) -> str helper. All 8 _cached_* functions now delegate to it instead of inlining hashlib.md5(image_bytes).hexdigest() with a manual f-string each time.

    # Before (repeated 8×)
    image_hash = hashlib.md5(image_bytes).hexdigest()
    key = f"severity_{image_hash}"
    return await _get_cached_result(key, detect_severity_clip, image_bytes)
    
    # After
    def _image_cache_key(prefix: str, image_bytes: bytes) -> str:
        return f"{prefix}_{hashlib.md5(image_bytes).hexdigest()}"
    
    async def _cached_detect_severity(image_bytes: bytes):
        return await _get_cached_result(_image_cache_key("severity", image_bytes), detect_severity_clip, image_bytes)
  • backend/routers/issues.py: Removed response_model=List[NearbyIssueResponse] from get_nearby_issues. The handler returns a pre-serialised fastapi.Response; keeping the annotation caused the generated OpenAPI schema to misrepresent the actual contract and bypassed no-op Pydantic validation.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Code style update (formatting, renaming)
  • ♻️ Refactoring (no functional changes)
  • ⚡ Performance improvement
  • ✅ Test update

Related Issue

Closes #

Testing Done

  • Tested locally
  • Added/updated tests
  • All tests passing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Co-Authors


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.


Summary by cubic

Consolidates image cache key generation into a single helper for deterministic keys and fewer cache misses. Also fixes a wrong response_model on the nearby issues route and a small indentation error.

  • Cache Stability

    • Extracted _image_cache_key(prefix, image_bytes) and used it across all 8 _cached_* functions for consistent MD5-based keys.
  • Bug Fixes

    • Removed incorrect response_model from GET /issues/nearby since it returns a raw Response.
    • Fixed an indentation issue that could cause parse/runtime errors.

Written for commit fea1bed. Summary will update on new commits.

…odel on get_nearby_issues

Co-authored-by: RohanExploit <178623867+RohanExploit@users.noreply.github.com>
Agent-Logs-Url: https://github.com/RohanExploit/VishwaGuru/sessions/10a14469-101a-4f94-9d2e-d0cc6c3a611a
Copilot AI changed the title [WIP] Fix indentation error and optimize cache stability Refactor: extract _image_cache_key helper and drop stale response_model on get_nearby_issues Mar 24, 2026
Copilot AI requested a review from RohanExploit March 24, 2026 17:18
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