Skip to content

Commit

Permalink
Adding more caching
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Jul 21, 2024
1 parent f406889 commit c0f492d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lazy_github/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class RepositorySettings(BaseModel):

class CacheSettings(BaseModel):
cache_directory: Path = CONFIG_FOLDER / ".cache"
default_ttl: int = int(timedelta(days=1).total_seconds())
default_ttl: int = int(timedelta(minutes=10).total_seconds())
list_repos_ttl: int = int(timedelta(days=1).total_seconds())
list_issues_ttl: int = int(timedelta(hours=1).total_seconds())


class AppearenceSettings(BaseModel):
Expand Down
5 changes: 2 additions & 3 deletions lazy_github/lib/github/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
async def _list(client: GithubClient, repo: Repository, state: IssueStateFilter) -> list[Issue]:
query_params = {"state": state}
user = await client.user()
response = await client.get(
f"/repos/{user.login}/{repo.name}/issues", headers=client.headers_with_auth_accept(), params=query_params
)
headers = client.headers_with_auth_accept(cache_duration=client.config.cache.list_issues_ttl)
response = await client.get(f"/repos/{user.login}/{repo.name}/issues", headers=headers, params=query_params)
result: list[Issue] = []
for issue in response.json():
if "draft" in issue:
Expand Down
3 changes: 2 additions & 1 deletion lazy_github/lib/github/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ async def _list(
per_page: int = 50,
) -> list[Repository]:
"""Retrieves Github repos matching the specified criteria"""
headers = client.headers_with_auth_accept(cache_duration=client.config.cache.list_repos_ttl)
query_params = {"type": repo_types, "direction": direction, "sort": sort, "page": page, "per_page": per_page}
response = await client.get("/user/repos", headers=client.headers_with_auth_accept(), params=query_params)
response = await client.get("/user/repos", headers=headers, params=query_params)
response.raise_for_status()
return [Repository(**r) for r in response.json()]

Expand Down

0 comments on commit c0f492d

Please sign in to comment.