Hub: reuse commit trees, ask for SHAs only, stream the model card

- listFiles() keeps the last trees it fetched by repo@SHA (a commit's files
  never change; capped at 50,000 files): adding a model right after the lookup
  no longer downloads the whole tree again. Callers get copies.
- addModel() fetches the author's avatar in parallel with the file list.
- The Hub check resolves revisions with resolveRevision(): /revision/<rev> with
  expand=sha, as huggingface_hub's model_info(expand=...) does, instead of the
  full model info (file list, card data, the Spaces using the model). Falls
  back to the full request if an answer comes without a SHA.
- The Model card tab renders inside <Suspense>: the page no longer waits for
  the README to arrive from the Hub (up to the 20 s timeout when it's slow).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EooZ9biu7kFNB4eDJrwQc5
This commit is contained in:
Claude committed 2026-11-01 21:04:05 +00:00
1 parent d58bff3437
commit 6f4932e04d
7 files changed
+189 -34

No files matched your search

+3 -2
View File
@@ -51,7 +51,8 @@ export async function addModel(input: {
});
if (existing) throw new ModelError("already_exists", `${repoId} is already in the library.`, 409);
const files = await listFiles(repoId, info.sha);
// Independent: the author's avatar loads while the file list does (usually cached from the lookup).
const [files, avatar] = await Promise.all([listFiles(repoId, info.sha), getAuthorAvatar(repoId.split("/")[0])]);
const selectedFiles = files.filter((f) => isSelected(f.path, input.rule));
if (selectedFiles.length === 0) {
throw new ModelError("empty_selection", "No files selected.", 400);
@@ -81,7 +82,7 @@ export async function addModel(input: {
localPath,
includePatterns: input.rule.include,
excludePatterns: input.rule.exclude,
...metadataColumns(info.metadata, await getAuthorAvatar(repoId.split("/")[0])),
...metadataColumns(info.metadata, avatar),
}),
d.insert(modelRevisions).values({ modelId, sha: info.sha }),
...chunk(fileRows, INSERT_CHUNK).map((c) => d.insert(modelFiles).values(c)),