From e04b3a38a4332d6711b1ea6ad6a7162b7d3ff3a5 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 13 Jul 2026 22:57:46 -0400 Subject: [PATCH] fix: get_file_commits use consistent caching (_cached/_set_cache) --- app/services/gitea_client.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/services/gitea_client.py b/app/services/gitea_client.py index ab660d2..71c6c73 100644 --- a/app/services/gitea_client.py +++ b/app/services/gitea_client.py @@ -387,14 +387,21 @@ class GiteaClient: del self._cache[k] async def get_file_commits(self, owner: str, repo: str, path: str) -> list[dict]: - """Get recent commits affecting a specific file.""" - url = f"{self.base}/api/v1/repos/{owner}/{repo}/commits" - params = {"path": path, "limit": 20} - headers = {"Authorization": f"token {self.token[0] if self.token else ''}", "Accept": "application/json"} - async with httpx.AsyncClient(timeout=self.timeout) as client: - resp = await client.get(url, params=params, headers=headers) + """Get recent commits affecting a specific file (cached 5 min).""" + key = f"commits:{owner}:{repo}:{path}" + cached = self._cached(key) + if cached: + return cached + async with httpx.AsyncClient(timeout=15) as client: + resp = await client.get( + f"{self._base}/repos/{owner}/{repo}/commits", + headers=self._headers, + params={"path": path, "limit": 20}, + ) if resp.status_code == 200: - return resp.json() + data = resp.json() + self._set_cache(key, data) + return data return []