-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Overview
Replace blocking requests.get() with async HTTP client in rate_limited_request() function.
Identified by: Copilot PR review on #7
Problem
The rate_limited_request() function is declared as async but uses the blocking requests.get() call, which can block the event loop and hurt performance.
File Affected
src/api.py:139inrate_limited_request()
Current Code
async def rate_limited_request(url: str, max_retries: int = 3, base_delay: float = 1.0) -> requests.Response:
# ...
response = requests.get(url, timeout=10) # ❌ Blocking call in async function
# ...Solution Options
- Use aiohttp (recommended - already a dependency)
- Use asyncio.to_thread() to offload to thread pool
- Use httpx (would need new dependency)
Recommended Implementation
import aiohttp
async def rate_limited_request(url: str, max_retries: int = 3, base_delay: float = 1.0) -> aiohttp.ClientResponse:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
# ... existing logicImpact
- Performance: Prevents event loop blocking
- Scalability: Better handling of concurrent requests
- Architecture: Maintains true async behavior throughout
Acceptance Criteria
- Replace
requests.get()withaiohttp - Update return type annotations
- Maintain existing retry logic and error handling
- All existing functionality works correctly
- No breaking changes to callers
Priority
Medium - Performance improvement, not a critical bug.
Related to linting infrastructure work but separate architectural concern.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request