feat(launch): cap per-user language fetch at 40 repos, raise enrollment caps, fix cap message

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shay
2026-11-29 10:30:52 -08:00
co-authored by Claude Opus 5.5
parent e47a67d1a1
commit 53ae54fe98
7 changed files with 50 additions and 5 deletions
+4
View File
@@ -31,5 +31,9 @@ DEEP_COLLAB_THRESHOLD = int(os.getenv("DEEP_COLLAB_THRESHOLD", "25"))
COMMIT_MAX_REPOS = int(os.getenv("COMMIT_MAX_REPOS", "10"))
COMMIT_PER_REPO = int(os.getenv("COMMIT_PER_REPO", "30"))
# Per-repo language-bytes fetches: one REST call each, so cap them to the
# most recently pushed repos the user owns (forks excluded).
LANGUAGE_MAX_REPOS = int(os.getenv("LANGUAGE_MAX_REPOS", "40"))
ANALYTICS_FLUSH_SECONDS = int(os.getenv("ANALYTICS_FLUSH_SECONDS", "5"))
ANALYTICS_QUEUE_MAX = int(os.getenv("ANALYTICS_QUEUE_MAX", "2000"))
+8 -2
View File
@@ -714,7 +714,7 @@ def fetch_github_data(
avatar_b64 = ""
avatar_url = user.get("avatar_url") if isinstance(user, dict) else None
with ThreadPoolExecutor(max_workers=2, thread_name_prefix="fetch-stage2") as pool:
fut_lang = pool.submit(_enrich_repo_languages, repos, source)
fut_lang = pool.submit(_enrich_repo_languages, repos, source, username)
fut_avatar = pool.submit(source.fetch_avatar, avatar_url) if avatar_url else None
fut_lang.result()
if fut_avatar is not None:
@@ -733,13 +733,19 @@ def fetch_github_data(
}
def _enrich_repo_languages(repos: list, source: GitHubDataSource) -> None:
def _enrich_repo_languages(repos: list, source: GitHubDataSource, username: str = "") -> None:
"""Mutates `repos` in-place, attaching `language_bytes: {lang: bytes}` to
each repo. Uses a small thread pool — one REST call per repo is cheap
individually, but sequentially N repos would block the fetch noticeably."""
if not repos:
return
names = [(i, r["full_name"]) for i, r in enumerate(repos) if r.get("full_name")]
if username:
owner = username.lower()
names = [(i, fn) for i, fn in names
if not repos[i].get("fork") and fn.split("/")[0].lower() == owner]
names.sort(key=lambda p: repos[p[0]].get("pushed_at") or "", reverse=True)
names = names[:config.LANGUAGE_MAX_REPOS]
print(f" Fetching language byte breakdown for {len(names)} repos...")
with ThreadPoolExecutor(max_workers=10) as pool:
futures = {pool.submit(source.fetch_repo_languages, fn): i for i, fn in names}
+27
View File
@@ -250,3 +250,30 @@ def test_rate_limited_repo_languages_aborts_whole_fetch():
repos = [{"full_name": "alice/proj"}]
with pytest.raises(github.GitHubTransientError):
github._enrich_repo_languages(repos, src)
def test_repo_languages_capped_to_recent_owned_repos(monkeypatch):
# One REST call per repo, so only the most recently pushed non-fork repos
# the user owns get a byte breakdown.
monkeypatch.setattr(github.config, "LANGUAGE_MAX_REPOS", 2)
class _Src:
def __init__(self):
self.calls = []
def fetch_repo_languages(self, full_name):
self.calls.append(full_name)
return {"Python": 1}
repos = [
{"full_name": "Alice/old", "pushed_at": "2024-01-01T00:00:00Z"},
{"full_name": "alice/new", "pushed_at": "2026-01-01T00:00:00Z"},
{"full_name": "alice/mid", "pushed_at": "2025-01-01T00:00:00Z"},
{"full_name": "alice/fork", "pushed_at": "2026-06-01T00:00:00Z", "fork": True},
{"full_name": "org/other", "pushed_at": "2026-06-01T00:00:00Z"},
]
src = _Src()
github._enrich_repo_languages(repos, src, "alice")
assert sorted(src.calls) == ["alice/mid", "alice/new"]
assert repos[1]["language_bytes"] == {"Python": 1}
assert "language_bytes" not in repos[0]