-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Bolt: Memoize validate_folder_url to skip redundant DNS lookups
#113
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import threading | ||
| import ipaddress | ||
| import socket | ||
| from functools import lru_cache | ||
| from urllib.parse import urlparse | ||
| from typing import Dict, List, Optional, Any, Set, Sequence | ||
|
|
||
|
|
@@ -192,7 +193,13 @@ def _api_client() -> httpx.Client: | |
| # --------------------------------------------------------------------------- # | ||
| _cache: Dict[str, Dict] = {} | ||
|
|
||
| @lru_cache(maxsize=128) | ||
| def validate_folder_url(url: str) -> bool: | ||
| """ | ||
| Validates a folder URL. | ||
| Cached to avoid repeated DNS lookups (socket.getaddrinfo) for the same URL | ||
| during warm-up and sync phases. | ||
| """ | ||
|
Comment on lines
+196
to
+202
|
||
| if not url.startswith("https://"): | ||
| log.warning(f"Skipping unsafe or invalid URL (must be https): {sanitize_for_log(url)}") | ||
| return False | ||
|
|
||
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.
Adding
lru_cacheto this function will suppress warning logs on subsequent calls with the same URL. The function logs warnings for various validation failures (unsafe URLs, localhost, private IPs, DNS resolution failures), but with caching enabled, these warnings will only appear the first time a URL is validated. Since this function is called in bothwarm_up_cacheandsync_profile, warnings will only be logged during warm-up. This is a minor behavioral change that could make debugging slightly harder if someone is investigating why a URL is being skipped in the sync phase, but is likely acceptable given the performance benefits.