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

+20
View File
@@ -0,0 +1,20 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { getLocalFolder } from "@/lib/local-folders";
export const dynamic = "force-dynamic";
/** One folder the scan found, with its files (`?path=<org>/<name>`): what the Import form needs. */
export const GET = withAuth(async (req) => {
const path = new URL(req.url).searchParams.get("path");
const folder = path ? await getLocalFolder(path) : undefined;
if (!folder) return apiError(404, "not_found", "This folder is no longer in the models folder. Rescan and try again.");
return NextResponse.json({
path: folder.path,
commit: folder.commit,
files: folder.files,
fileCount: folder.fileCount,
totalBytes: folder.totalBytes,
});
});