π Problem Statement
AegisAI's recently shipped compliance badge feature (GET /badge/{system_id}/svg) generates a live SVG badge showing an AI system's compliance status. These badges are designed to be embedded in READMEs and documentation. However, README badge embeds are fetched by GitHub's Camo image proxy every time someone views the README β potentially hundreds of times per hour for popular repositories.
Without Cache-Control and ETag headers on the badge endpoint:
- Every badge render triggers a full database query to look up the AI system's compliance status
- GitHub Camo will re-fetch the badge on every page view rather than serving a cached version
- Under moderate traffic, this creates a significant unnecessary database load that scales with repository popularity
Proposed Fix
Add appropriate HTTP caching headers to the badge endpoint in backend/app/api/v1/badge.py:
from fastapi import APIRouter, Response
from datetime import timedelta
import hashlib
router = APIRouter()
@router.get("/{system_id}/svg")
async def get_compliance_badge(
system_id: str,
db: AsyncSession = Depends(get_db),
response: Response = None,
):
system = await db.get(AISystem, system_id)
if not system:
raise HTTPException(status_code=404)
svg_content = generate_badge_svg(system.risk_level, system.compliance_status)
# Generate ETag from content hash so clients only re-fetch when status changes
etag = hashlib.md5(svg_content.encode()).hexdigest()
response.headers["Content-Type"] = "image/svg+xml"
response.headers["Cache-Control"] = "public, max-age=3600, s-maxage=3600" # 1 hour
response.headers["ETag"] = f'"{etag}"'
response.headers["Vary"] = "Accept-Encoding"
return Response(content=svg_content, media_type="image/svg+xml", headers=response.headers)
Also add Redis caching for the compliance status lookup:
CACHE_KEY = f"badge:{system_id}"
CACHE_TTL = 3600 # 1 hour
cached = await redis.get(CACHE_KEY)
if cached:
return Response(content=cached, media_type="image/svg+xml")
# ... generate badge, then cache:
await redis.setex(CACHE_KEY, CACHE_TTL, svg_content)
Cache should be invalidated when the system's compliance status is updated via PATCH /ai-systems/{id}.
Files to Modify
| File |
Change |
backend/app/api/v1/badge.py |
Add Cache-Control, ETag headers + Redis cache |
backend/app/api/v1/ai_systems.py |
Invalidate badge cache on status update |
Suggested labels: enhancement, performance, backend, level: beginner
I would like to work on this. Could you please assign it to me?
π Problem Statement
AegisAI's recently shipped compliance badge feature (
GET /badge/{system_id}/svg) generates a live SVG badge showing an AI system's compliance status. These badges are designed to be embedded in READMEs and documentation. However, README badge embeds are fetched by GitHub's Camo image proxy every time someone views the README β potentially hundreds of times per hour for popular repositories.Without
Cache-ControlandETagheaders on the badge endpoint:Proposed Fix
Add appropriate HTTP caching headers to the badge endpoint in
backend/app/api/v1/badge.py:Also add Redis caching for the compliance status lookup:
Cache should be invalidated when the system's compliance status is updated via
PATCH /ai-systems/{id}.Files to Modify
backend/app/api/v1/badge.pyCache-Control,ETagheaders + Redis cachebackend/app/api/v1/ai_systems.pySuggested labels:
enhancement,performance,backend,level: beginnerI would like to work on this. Could you please assign it to me?