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:
7 files changed
+189
-34
No files matched your search
@@ -6,7 +6,7 @@ import { and, asc, eq, isNull, lt, or } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { type HubState, modelFiles, models, type UpdateDiff } from "@/lib/db/schema";
|
||||
import { computeUpdateDiff } from "@/lib/update-diff";
|
||||
import { getRepoInfo, HubError, listFiles, SHA_RE } from "./client";
|
||||
import { HubError, listFiles, resolveRevision, SHA_RE } from "./client";
|
||||
|
||||
type CheckedModel = Pick<
|
||||
typeof models.$inferSelect,
|
||||
@@ -45,7 +45,7 @@ const isGated = (err: unknown) => err instanceof HubError && (err.code === "gate
|
||||
/** Resolve a revision to its commit; null if the Hub says the revision doesn't exist. */
|
||||
async function resolve(repoId: string, revision: string): Promise<string | null> {
|
||||
try {
|
||||
return (await getRepoInfo(repoId, revision)).sha;
|
||||
return await resolveRevision(repoId, revision);
|
||||
} catch (err) {
|
||||
if (err instanceof HubError && err.code === "revision_not_found") return null;
|
||||
throw err;
|
||||
|
||||
Reference in new issue
Block a user