fix(api): keep weekly gitea stats fast
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user