Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

Adding lru_cache to 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 both warm_up_cache and sync_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.

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +202
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The lru_cache decorator caches based on the full URL, but the expensive DNS lookup (line 228) only depends on the hostname. For a future optimization, consider caching hostname validation separately from URL validation. This would be particularly beneficial when multiple URLs share the same hostname (as is the case with the default configuration where all URLs use raw.githubusercontent.com), reducing DNS lookups from one per URL to one per unique hostname.

Copilot uses AI. Check for mistakes.
if not url.startswith("https://"):
log.warning(f"Skipping unsafe or invalid URL (must be https): {sanitize_for_log(url)}")
return False
Expand Down
Loading