Skip to content
Merged
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
## 2024-11-20 - JSON Decoding Performance - Index Advancement
**Learning:** Even when avoiding string slicing using `json.JSONDecoder().raw_decode(text, index)`, failing to correctly advance the index by ignoring the returned `end` index (`value, _ = decoder.raw_decode(...)`) forces the search loop to repeatedly attempt to decode nested JSON structures (e.g., inner braces `{`) sequentially. This leads to massive O(N^2) time complexity and redundant parsing for large, deeply nested JSON objects.
**Action:** Always capture and use the new end index returned by `raw_decode` (e.g., `value, next_idx = decoder.raw_decode(text, index)`) to jump over the completely parsed object and proceed efficiently.
## 2025-02-23 - GitHub API N+1 Query Optimization
**Learning:** In scripts parsing GitHub PR lists, fetching REST API attributes (`fetch_rest_mergeable_state`) for each PR sequentially creates a severe N+1 HTTP request bottleneck.
**Action:** Use `concurrent.futures.ThreadPoolExecutor` to parallelize multiple independent network calls instead of doing them sequentially.
9 changes: 8 additions & 1 deletion scripts/ci/pr_review_merge_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
from collections.abc import Sequence
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any
Expand Down Expand Up @@ -407,12 +408,18 @@ def fetch_rest_mergeable_state(repo: str, number: int) -> str:

def enrich_rest_mergeable_states(repo: str, prs: list[dict[str, Any]]) -> None:
"""Attach REST mergeability evidence to GraphQL pull request payloads."""
for pr in prs:
def _fetch_state(pr: dict[str, Any]) -> None:
try:
pr["restMergeableState"] = fetch_rest_mergeable_state(repo, int(pr["number"]))
except RuntimeError as exc:
pr["restMergeableStateError"] = bounded_error_summary(str(exc))

# ⚡ Bolt Optimization: Use ThreadPoolExecutor to prevent N+1 HTTP request bottleneck
# when sequentially fetching mergeability states for multiple PRs from the REST API.
with ThreadPoolExecutor(max_workers=min(10, len(prs) or 1)) as executor:
for _ in executor.map(_fetch_state, prs):
pass
Comment thread
Copilot marked this conversation as resolved.
Outdated


def effective_merge_state(pr: dict[str, Any]) -> str:
"""Return the safest merge state from GraphQL plus REST mergeability evidence."""
Expand Down
Loading