Library: load import folder files on demand, memoize search

The library page passed every importable folder's full file list (up to 5,000
entries each, from the worker's scan) into a client component, though it is
only used after clicking Import. With three such folders that was 84% of a
1.3 MB page, re-sent on every refresh after a job finished.

- listLocalFolders() returns path, commit and counts only; the Import button
  fetches one folder's files from GET /api/local-folders?path=…
- addModel() checks that an import folder exists without loading its files.
- LibraryView builds each model's search text once and memoizes the visible
  rows and facet counts; the facet sort uses one Intl.Collator.

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 20:49:18 +00:00
1 parent 76d851896e
commit 7239ba2692
9 files changed
+110 -31

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@ import { hubMissingMessage } from "@/lib/hub/availability";
import { checkFileAccess, getAuthorAvatar, getRepoInfo, listFiles } from "@/lib/hub/client";
import { metadataColumns } from "@/lib/hub/refresh";
import { hasOpenJob, queueDownload } from "@/lib/jobs";
import { getLocalFolder, requestFolderScan } from "@/lib/local-folders";
import { localFolderExists, requestFolderScan } from "@/lib/local-folders";
import { purgeModelRows } from "@/lib/model-purge";
import { contentId } from "@/lib/update-diff";
import { escapeGlob, isSelected, matchesAny, type SelectionRule } from "@/lib/selection";
@@ -39,7 +39,7 @@ export async function addModel(input: {
const info = await getRepoInfo(input.repoId, input.sha);
const repoId = info.repoId;
const localPath = input.localPath ?? repoId;
if (input.localPath && !(await getLocalFolder(input.localPath))) {
if (input.localPath && !(await localFolderExists(input.localPath))) {
throw new ModelError("not_found", `Folder ${input.localPath} was not found in the models folder. Rescan and try again.`, 404);
}
const usedBy = await db().query.models.findFirst({ columns: { repoId: true }, where: eq(models.localPath, localPath) });