fix: get_file_commits use consistent caching (_cached/_set_cache)
This commit is contained in:
@@ -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 []
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user