fix(api): keep weekly gitea stats fast
All checks were successful
Code Review / ai-code-review (push) Successful in 13s
CD Pipeline / tests (push) Successful in 1m40s
CD Pipeline / build-and-deploy (push) Successful in 5m18s
CD Pipeline / post-deploy-checks (push) Successful in 1m39s

This commit is contained in:
Your Name
2026-06-27 16:47:35 +08:00
parent c77cb4ccee
commit 7406d229bb
2 changed files with 5 additions and 5 deletions

View File

@@ -160,7 +160,7 @@ class WeeklyReportService:
deploys = 0
page = 1
limit = 50
max_pages = 4
max_pages = 1
try:
for api_url in self._gitea_api_candidates():
for headers in header_candidates:
@@ -177,7 +177,7 @@ class WeeklyReportService:
})
url = f"{api_url}/api/v1/repos/{owner}/{repo}/commits?{query}"
request = Request(url, headers=headers)
with urlopen(request, timeout=2) as response:
with urlopen(request, timeout=1) as response:
total_header = response.headers.get("X-Total-Count") or response.headers.get("X-Total")
if total_header and total_header.isdigit():
total_commits = int(total_header)
@@ -217,7 +217,7 @@ class WeeklyReportService:
def _gitea_api_candidates(self) -> list[str]:
"""取得 Git 統計可用的 Gitea read-only API base URLs。"""
candidates = [settings.GITEA_API_URL.rstrip("/"), "https://gitea.wooo.work"]
candidates = ["https://gitea.wooo.work", settings.GITEA_API_URL.rstrip("/")]
deduped: list[str] = []
for candidate in candidates:
if candidate and candidate not in deduped:

View File

@@ -151,7 +151,7 @@ class TestWeeklyReportGitStats:
def fake_urlopen(request, timeout):
assert "/api/v1/repos/wooo/awoooi/commits?" in request.full_url
assert timeout == 2
assert timeout == 1
assert "Authorization" not in request.headers
return Response()
@@ -236,7 +236,7 @@ class TestWeeklyReportGitStats:
assert commits == 4804
assert deploys == 0
assert source_ok is True
assert len(calls) == 4
assert len(calls) == 1
# =============================================================================