Skip to content

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

Merged
RohanExploit merged 2 commits into
bolt-optimization-cache-serialization-14526281583048350032from
copilot/sub-pr-573
Mar 29, 2026
Merged

Refactor: extract _image_cache_key helper and drop stale response_model on get_nearby_issues#587
RohanExploit merged 2 commits into
bolt-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
@RohanExploit RohanExploit marked this pull request as ready for review March 29, 2026 14:28
Copilot AI review requested due to automatic review settings March 29, 2026 14:28
@RohanExploit RohanExploit merged commit d004b76 into bolt-optimization-cache-serialization-14526281583048350032 Mar 29, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors cache-key generation for image-based detection helpers and corrects the FastAPI contract for the nearby-issues endpoint by removing a misleading response_model that didn’t match the actual raw Response return type.

Changes:

  • Extracted _image_cache_key(prefix, image_bytes) to de-duplicate deterministic MD5 cache-key construction across cached detection helpers.
  • Removed response_model=List[NearbyIssueResponse] from GET /issues/nearby to align OpenAPI with the endpoint’s raw Response behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/routers/detection.py Centralizes deterministic image cache-key construction into _image_cache_key and updates cached helper functions to use it.
backend/routers/issues.py Removes an incorrect response_model from /issues/nearby to match the handler’s raw Response return type and avoid misleading OpenAPI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants