Skip to content

Commit

Permalink
faster cache file resize
Browse files Browse the repository at this point in the history
  • Loading branch information
jstzwj committed Aug 6, 2024
1 parent ea97ba0 commit 366e898
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions olah/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class AppSettings(BaseSettings):
# See also: https://huggingface.co/docs/hub/api#repo-listing-api
# ======================
async def meta_proxy_common(repo_type: str, org: str, repo: str, commit: str, request: Request) -> Response:
# TODO: the head method of meta apis
# FIXME: do not show the private repos to other user besides owner, even though the repo was cached
if repo_type not in REPO_TYPES_MAPPING.keys():
return error_page_not_found()
if not await check_proxy_rules_hf(app, repo_type, org, repo):
Expand Down
11 changes: 8 additions & 3 deletions olah/utils/olah_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,16 @@ def _resize_file_size(self, file_size: int):
f.seek(0, os.SEEK_END)
bin_size = f.tell()

# FIXME: limit the resize method, because it may influence the _block_mask
new_bin_size = self._get_header_size() + file_size
with open(self.path, "rb+") as f:
# Extend file size
f.seek(0, os.SEEK_END)
f.write(b"\x00" * (new_bin_size - bin_size))
f.seek(new_bin_size - 1)
f.write(b'\0')
f.truncate()

# Extend file size (slow)
# f.seek(0, os.SEEK_END)
# f.write(b"\x00" * (new_bin_size - bin_size))

def resize(self, file_size: int):
if not self.is_open:
Expand Down

0 comments on commit 366e898

Please sign in to comment.