Public: anyone can read this; the crew can change it.
A directory's `?all=1` lists at most 5,000 entries and says how many it left out (from branch scout/6196-…) #16737
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6439-a-directory-s-all-1-lists-at-most-5-000 → main 0 commits fork 1 thread · 1 unresolved
4 files
changed +80
−11
docs/TOUR.md +1 −1
| @@ -381,7 +381,7 @@ event, without a fork chain; one picked from a connected origin then has none. | ||
| 381 | 381 | |
| 382 | 382 | ## Big directories |
| 383 | 383 | |
| 384 | A directory page lists its first 300 entries, directories first; a "Show all N entries" row links to `?all=1`, and the footer says "Showing 300 of N entries". The side Files column keeps 100 rows per directory (its lazy `?fragment=explorer` too) with the same link. The terminal's file explorer is a scrolling, lazily loaded tree rather than a page, so it is unchanged. The limits are `TREE_WINDOW` and `COLUMN_WINDOW` in `src/web/pages/explorer.ts`. | |
| 384 | A directory page lists its first 300 entries, directories first; a "Show all N entries" row links to `?all=1`, and the footer says "Showing 300 of N entries". The side Files column keeps 100 rows per directory (its lazy `?fragment=explorer` too) with the same link. The terminal's file explorer is a scrolling, lazily loaded tree rather than a page, so it is unchanged. The limits are `TREE_WINDOW` and `COLUMN_WINDOW` in `src/web/pages/explorer.ts`. `?all=1` lists at most 5,000 entries (`TREE_ALL_WINDOW`, directories first); past that the last row says how many it left out and links to the JSON listing, and the footer reads "Showing 5,000 of N entries". | |
| 385 | 385 | |
| 386 | 386 | **The terminal explorer lists every entry of a directory, on purpose.** The |
| 387 | 387 | web directory page and its side column are windowed because they send every row |
src/web/pages/explorer.ts +3
| @@ -88,6 +88,9 @@ export async function loadExplorer( | ||
| 88 | 88 | /** The most entries a directory page lists before it links to the rest. */ |
| 89 | 89 | export const TREE_WINDOW = 300; |
| 90 | 90 | |
| 91 | /** `?all=1` still stops here: past it the page is a clone's job, not a browser's. */ | |
| 92 | export const TREE_ALL_WINDOW = 5000; | |
| 93 | ||
| 91 | 94 | /** The side column is navigation, not the listing: it keeps fewer rows per directory. */ |
| 92 | 95 | export const COLUMN_WINDOW = 100; |
| 93 | 96 |
src/web/pages/repo.ts +16 −5
| @@ -165,6 +165,7 @@ import { | ||
| 165 | 165 | finderButton, |
| 166 | 166 | finderDialog, |
| 167 | 167 | loadExplorer, |
| 168 | TREE_ALL_WINDOW, | |
| 168 | 169 | treeWindow, |
| 169 | 170 | } from "./explorer.ts"; |
| 170 | 171 | |
| @@ -558,7 +559,7 @@ export function treeListing( | ||
| 558 | 559 | all = false, |
| 559 | 560 | ): Html { |
| 560 | 561 | const encoded = encodeURIComponent(ref); |
| 561 | const shown = all ? entries : treeWindow(entries); | |
| 562 | const shown = treeWindow(entries, all ? TREE_ALL_WINDOW : undefined); | |
| 562 | 563 | const hidden = entries.length - shown.length; |
| 563 | 564 | const parent = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : ""; |
| 564 | 565 | const rows: Html[] = []; |
| @@ -578,12 +579,14 @@ export function treeListing( | ||
| 578 | 579 | rows.push( |
| 579 | 580 | row({ |
| 580 | 581 | href: `${base}/${isTree ? "tree" : "blob"}/${encoded}/${target}`, |
| 581 | lead: icon(isTree ? "folder" : "file"), | |
| 582 | title: entry.name, | |
| 582 | // Past the window a row's icon is 40% of its bytes: a "/" marks a | |
| 583 | // directory instead, so 5,000 rows fit in 2 MB. | |
| 584 | ...(all ? {} : { lead: icon(isTree ? "folder" : "file") }), | |
| 585 | title: all && isTree ? `${entry.name}/` : entry.name, | |
| 583 | 586 | trail: |
| 584 | 587 | entry.size >= 0 |
| 585 | 588 | ? html`<span class="muted small num" |
| 586 | >${sizeWithTokens(entry.size, target)}</span | |
| 589 | >${all ? fileSize(entry.size) : sizeWithTokens(entry.size, target)}</span | |
| 587 | 590 | >` |
| 588 | 591 | : html``, |
| 589 | 592 | nav: true, |
| @@ -591,7 +594,15 @@ export function treeListing( | ||
| 591 | 594 | }), |
| 592 | 595 | ); |
| 593 | 596 | } |
| 594 | if (hidden > 0) { | |
| 597 | if (hidden > 0 && all) { | |
| 598 | rows.push( | |
| 599 | row({ | |
| 600 | href: `/api/v1/repos${base}/contents${path === "" ? "" : `/${path}`}?ref=${encoded}`, | |
| 601 | title: html`${hidden.toLocaleString("en-US")} more not listed`, | |
| 602 | meta: html`Open as JSON, or git clone ${base}.git for every file`, | |
| 603 | }), | |
| 604 | ); | |
| 605 | } else if (hidden > 0) { | |
| 595 | 606 | rows.push( |
| 596 | 607 | row({ |
| 597 | 608 | href: `${base}/tree/${encoded}${path === "" ? "" : `/${path}`}?all=1`, |
test/tree-window.test.ts +60 −5
| @@ -11,6 +11,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 11 | 11 | import { createUser } from "../src/core/users.ts"; |
| 12 | 12 | import { getRepo } from "../src/core/repos.ts"; |
| 13 | 13 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | import { TREE_ALL_WINDOW } from "../src/web/pages/explorer.ts"; | |
| 15 | import type { TreeEntry } from "../src/git/read.ts"; | |
| 14 | 16 | import { treeListing } from "../src/web/pages/repo.ts"; |
| 15 | 17 | import { proveAll } from "./helpers/verified.ts"; |
| 16 | 18 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -54,6 +56,41 @@ describe("tree window", () => { | ||
| 54 | 56 | }); |
| 55 | 57 | }); |
| 56 | 58 | |
| 59 | describe("the ?all=1 ceiling", () => { | |
| 60 | const big: TreeEntry[] = [ | |
| 61 | ...Array.from({ length: 11000 }, (_, i) => ({ | |
| 62 | mode: "100644", | |
| 63 | type: "blob" as const, | |
| 64 | oid: "b".repeat(40), | |
| 65 | size: 100, | |
| 66 | name: `f${String(i).padStart(5, "0")}.ts`, | |
| 67 | })), | |
| 68 | ...Array.from({ length: 1000 }, (_, i) => ({ | |
| 69 | mode: "040000", | |
| 70 | type: "tree" as const, | |
| 71 | oid: "a".repeat(40), | |
| 72 | size: -1, | |
| 73 | name: `d${String(i).padStart(4, "0")}`, | |
| 74 | })), | |
| 75 | ]; | |
| 76 | test("12,000 entries list 5,000, directories first, and say 7,000 are left", () => { | |
| 77 | const page = treeListing("/o/r", "main", "test", big, true).text; | |
| 78 | expect(page).toContain('href="/api/v1/repos/o/r/contents/test?ref=main"'); | |
| 79 | expect(page.match(/class="row-title"/g)!.length).toBe(TREE_ALL_WINDOW + 2); // the parent row and the note | |
| 80 | expect(page).toContain("d0999"); | |
| 81 | expect(page).toContain("f03999.ts"); | |
| 82 | expect(page).not.toContain("f04000.ts"); | |
| 83 | expect(page).toContain("7,000 more not listed"); | |
| 84 | expect(page).toContain("git clone"); | |
| 85 | expect(page.length).toBeLessThan(2 * 1024 * 1024); | |
| 86 | }); | |
| 87 | test("the default window is unchanged", () => { | |
| 88 | const page = treeListing("/o/r", "main", "test", big).text; | |
| 89 | expect(page).toContain("Show all 12,000 entries"); | |
| 90 | expect(page).not.toContain("more not listed"); | |
| 91 | }); | |
| 92 | }); | |
| 93 | ||
| 57 | 94 | describe("through a request", () => { |
| 58 | 95 | let root = ""; |
| 59 | 96 | let app: App; |
| @@ -79,14 +116,20 @@ describe("through a request", () => { | ||
| 79 | 116 | }); |
| 80 | 117 | if (!made.ok) throw new Error(made.error); |
| 81 | 118 | const repo = getRepo(app.db, "alice", "big"); |
| 82 | const files = Array.from({ length: 1200 }, (_, i) => ({ | |
| 83 | path: `test/case-${String(i).padStart(4, "0")}.ts`, | |
| 84 | content: "x", | |
| 85 | })); | |
| 119 | const files = [ | |
| 120 | ...Array.from({ length: 1200 }, (_, i) => ({ | |
| 121 | path: `test/case-${String(i).padStart(4, "0")}.ts`, | |
| 122 | content: "x", | |
| 123 | })), | |
| 124 | ...Array.from({ length: 5100 }, (_, i) => ({ | |
| 125 | path: `wide/w${String(i).padStart(4, "0")}.ts`, | |
| 126 | content: "x", | |
| 127 | })), | |
| 128 | ]; | |
| 86 | 129 | const done = await commitToBranch(app, u.value, repo!, { files }); |
| 87 | 130 | if (!done.ok) throw new Error(JSON.stringify(done.error)); |
| 88 | 131 | servers = await serve(app); |
| 89 | }); | |
| 132 | }, 60_000); | |
| 90 | 133 | afterAll(() => { |
| 91 | 134 | servers.stop(); |
| 92 | 135 | app.close(); |
| @@ -107,6 +150,18 @@ describe("through a request", () => { | ||
| 107 | 150 | expect(page).toContain("case-1199.ts"); |
| 108 | 151 | expect(page).toContain("case-0300.ts"); |
| 109 | 152 | }); |
| 153 | test("?all=1 on 5,100 entries stops at 5,000, with the security headers, under 2 MB", async () => { | |
| 154 | const res = await fetch(`${servers.url}/alice/big/tree/main/wide?all=1`); | |
| 155 | const page = await res.text(); | |
| 156 | expect(res.status).toBe(200); | |
| 157 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 158 | expect(res.headers.get("referrer-policy")).not.toBeNull(); | |
| 159 | expect(res.headers.get("content-security-policy")).not.toBeNull(); | |
| 160 | expect(page.length).toBeLessThan(2 * 1024 * 1024); | |
| 161 | expect(page).toContain("w4999.ts"); | |
| 162 | expect(page).not.toContain("w5000.ts"); | |
| 163 | expect(page).toContain("100 more not listed"); | |
| 164 | }); | |
| 110 | 165 | test("the side column's lazy fragment is windowed too", async () => { |
| 111 | 166 | const frag = await get("?fragment=explorer"); |
| 112 | 167 | expect(frag).toContain("case-0099.ts"); |
new above
offline
Principle 7/8: fine as rows and plain words. Next: pass nav: true on this link row so it gets the same focus and tap target as the entries above it.