Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
## 2024-05-24 - Pass Local State to Avoid Redundant Reads
**Learning:** When a process involves modifying remote state (e.g. deleting folders) and then querying it (e.g. getting rules from remaining folders), maintaining a local replica of the state avoids redundant API calls. If you know what you deleted, you don't need to ask the server "what's left?".
**Action:** Identify sequences of "Read -> Modify -> Read" and optimize to "Read -> Modify (update local) -> Use local".

## 2024-05-24 - Parallelize DNS Validation
**Learning:** DNS lookups (`socket.getaddrinfo`) are blocking I/O operations. Performing them sequentially in a list comprehension (e.g., to filter URLs) can be a major bottleneck. Parallelizing them alongside the fetch operation can significantly reduce startup time.
**Action:** Move validation logic that involves network I/O into the parallel worker thread instead of pre-filtering sequentially.
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,25 @@ def fetch_folder_data(url: str) -> Dict[str, Any]:

def warm_up_cache(urls: Sequence[str]) -> None:
urls = list(set(urls))
urls_to_fetch = [u for u in urls if u not in _cache and validate_folder_url(u)]
# Optimization: Filter out already cached URLs (content check)
urls_to_fetch = [u for u in urls if u not in _cache]
if not urls_to_fetch:
return

total = len(urls_to_fetch)
if not USE_COLORS:
log.info(f"Warming up cache for {total} URLs...")
Comment on lines 477 to 479
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The progress counter now includes URLs that fail validation, which may be misleading. In the previous implementation, total only counted URLs that passed validation. Now it counts all non-cached URLs, including those that will fail validation and never be fetched. Consider updating the progress messages to clarify this, or decrement the total for URLs that fail validation.

Copilot uses AI. Check for mistakes.

# Helper function to validate AND fetch in the worker thread
# Validation involves DNS lookups (blocking I/O), so parallelization is critical.
def _validate_and_fetch(url: str) -> None:
if validate_folder_url(url):
_gh_get(url)
Comment on lines +483 to +485
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The new parallel validation logic in _validate_and_fetch lacks test coverage. Since the repository has comprehensive automated testing for similar functions (e.g., push_rules, get_all_existing_rules, check_api_access), consider adding tests that verify: (1) URLs that fail validation are not cached, (2) URLs that pass validation are properly cached via _gh_get, and (3) the parallel execution completes successfully with both valid and invalid URLs.

Copilot uses AI. Check for mistakes.

completed = 0
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = {executor.submit(_gh_get, url): url for url in urls_to_fetch}
# Submit task that does both validation and fetch
futures = {executor.submit(_validate_and_fetch, url): url for url in urls_to_fetch}

if USE_COLORS:
sys.stderr.write(f"\r{Colors.CYAN}⏳ Warming up cache: 0/{total}...{Colors.ENDC}")
Expand Down
Loading