-
Notifications
You must be signed in to change notification settings - Fork 0
Cache API settings helper #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from sqlalchemy.exc import IntegrityError | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from api.config import get_settings | ||
| from api.db import get_db | ||
| from api.models import SyncEvent | ||
| from api.security import require_write_token, validate_hygraph_request | ||
|
|
@@ -32,7 +33,15 @@ | |
| logger = logging.getLogger(__name__) | ||
| router = APIRouter(prefix="/api/sync", tags=["sync"]) | ||
|
|
||
| # Using hygraph_token as webhook secret in MVP; adjust if separate secret provided | ||
| settings = get_settings() | ||
| _hygraph_service = HygraphService(webhook_secret=settings.hygraph_token) | ||
|
Comment on lines
+36
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chainVerify initialization safety and confirm Module-level initialization creates several concerns:
Run the following script to verify the 🏁 Script executed: #!/bin/bash
# Verify lru_cache decorator and find test files
echo "=== Checking get_settings implementation for lru_cache decorator ==="
rg -A 3 -B 1 'def get_settings' backend/api/config.py
echo -e "\n=== Finding test files that might mock or use HygraphService ==="
fd -e py test backend/tests --exec rg -l 'HygraphService|routes_sync'
echo -e "\n=== Checking for existing test patterns around settings ==="
rg -n 'Settings|get_settings' backend/tests/ --type py -C 2 2>/dev/null || echo "No tests directory found or no matches"Length of output: 359 Lazy-initialize HygraphService instead of module-level instantiation 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def get_hygraph_service() -> HygraphService: | ||
| """Provide the shared Hygraph service instance.""" | ||
|
|
||
| return _hygraph_service | ||
| def _error_envelope(code: str, message: str, details: Optional[dict] = None) -> Dict[str, Any]: | ||
| return {"ok": False, "error": {"code": code, "message": message, "details": details or {}}} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider making the cache size explicit.
The implementation is correct, but since
get_settings()takes no parameters, only one instance will ever be cached. Consider using@lru_cache(no parentheses) or@lru_cache(maxsize=1)to make the singleton intent clearer.🤖 Prompt for AI Agents