Skip to content

Commit

Permalink
offline bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jstzwj committed Nov 5, 2024
1 parent 4be5ed1 commit 485d773
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions olah/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ def read_toml(self, path: str) -> None:
if "accessibility" in config:
accessibility = config["accessibility"]
self.offline = accessibility.get("offline", self.offline)
self.proxy = OlahRuleList.from_list(accessibility.get("proxy", self.proxy))
self.cache = OlahRuleList.from_list(accessibility.get("cache", self.cache))
self.proxy = OlahRuleList.from_list(accessibility.get("proxy", DEFAULT_PROXY_RULES))
self.cache = OlahRuleList.from_list(accessibility.get("cache", DEFAULT_CACHE_RULES))
64 changes: 58 additions & 6 deletions olah/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ async def meta_proxy_common(repo_type: str, org: str, repo: str, commit: str, me
return error_repo_not_found()
# if branch name and online mode, refresh branch info
if not app.app_settings.config.offline and commit_sha != commit:
generator = meta_generator(
app=app,
repo_type=repo_type,
org=org,
repo=repo,
commit=commit,
override_cache=True,
method=method,
authorization=authorization,
)
async for _ in generator:
pass
generator = meta_generator(
app=app,
repo_type=repo_type,
Expand Down Expand Up @@ -387,6 +399,21 @@ async def tree_proxy_common(
return error_repo_not_found()
# if branch name and online mode, refresh branch info
if not app.app_settings.config.offline and commit_sha != commit:
generator = tree_generator(
app=app,
repo_type=repo_type,
org=org,
repo=repo,
commit=commit,
path=path,
recursive=recursive,
expand=expand,
override_cache=True,
method=method,
authorization=authorization,
)
async for _ in generator:
pass
generator = tree_generator(
app=app,
repo_type=repo_type,
Expand Down Expand Up @@ -516,12 +543,25 @@ async def pathsinfo_proxy_common(repo_type: str, org: str, repo: str, commit: st
return error_repo_not_found()
if not app.app_settings.config.offline and commit_sha != commit:
generator = pathsinfo_generator(
app,
repo_type,
org,
repo,
commit_sha,
paths,
app=app,
repo_type=repo_type,
org=org,
repo=repo,
commit=commit,
paths=paths,
override_cache=True,
method=method,
authorization=authorization,
)
async for _ in generator:
pass
generator = pathsinfo_generator(
app=app,
repo_type=repo_type,
org=org,
repo=repo,
commit=commit_sha,
paths=paths,
override_cache=True,
method=method,
authorization=authorization,
Expand Down Expand Up @@ -630,6 +670,18 @@ async def commits_proxy_common(repo_type: str, org: str, repo: str, commit: str,
return error_repo_not_found()
# if branch name and online mode, refresh branch info
if not app.app_settings.config.offline and commit_sha != commit:
generator = commits_generator(
app=app,
repo_type=repo_type,
org=org,
repo=repo,
commit=commit,
override_cache=True,
method=method,
authorization=authorization,
)
async for _ in generator:
pass
generator = commits_generator(
app=app,
repo_type=repo_type,
Expand Down
9 changes: 5 additions & 4 deletions olah/utils/repo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from urllib.parse import urljoin
import httpx
from olah.constants import WORKER_API_TIMEOUT
from olah.utils.cache_utils import read_cache_request


def get_org_repo(org: Optional[str], repo: str) -> str:
Expand Down Expand Up @@ -74,7 +75,7 @@ def get_meta_save_path(
"""
return os.path.join(
repos_path, f"api/{repo_type}/{org}/{repo}/revision/{commit}/meta.json"
repos_path, f"api/{repo_type}/{org}/{repo}/revision/{commit}/meta_get.json"
)


Expand Down Expand Up @@ -226,9 +227,9 @@ async def get_commit_hf_offline(
repos_path = app.app_settings.config.repos_path
save_path = get_meta_save_path(repos_path, repo_type, org, repo, commit)
if os.path.exists(save_path):
with open(save_path, "r", encoding="utf-8") as f:
obj = json.loads(f.read())
return obj["sha"]
request_cache = await read_cache_request(save_path)
request_cache_json = json.loads(request_cache["content"])
return request_cache_json["sha"]
else:
return None

Expand Down

0 comments on commit 485d773

Please sign in to comment.