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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/6439-a-directory-s-all-1-lists-at-most-5-000 → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/6439-a-directory-s-all-1-lists-at-most-5-000 was merged into main as d2be40c.

Review

Sign in to review this change.
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.
381381
382382 ## Big directories
383383
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".
385385
386386 **The terminal explorer lists every entry of a directory, on purpose.** The
387387 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(
8888 /** The most entries a directory page lists before it links to the rest. */
8989 export const TREE_WINDOW = 300;
9090
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
9194 /** The side column is navigation, not the listing: it keeps fewer rows per directory. */
9295 export const COLUMN_WINDOW = 100;
9396
src/web/pages/repo.ts +16 −5
@@ -165,6 +165,7 @@ import {
165165 finderButton,
166166 finderDialog,
167167 loadExplorer,
168 TREE_ALL_WINDOW,
168169 treeWindow,
169170 } from "./explorer.ts";
170171
@@ -558,7 +559,7 @@ export function treeListing(
558559 all = false,
559560 ): Html {
560561 const encoded = encodeURIComponent(ref);
561 const shown = all ? entries : treeWindow(entries);
562 const shown = treeWindow(entries, all ? TREE_ALL_WINDOW : undefined);
562563 const hidden = entries.length - shown.length;
563564 const parent = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
564565 const rows: Html[] = [];
@@ -578,12 +579,14 @@ export function treeListing(
578579 rows.push(
579580 row({
580581 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,
583586 trail:
584587 entry.size >= 0
585588 ? html`<span class="muted small num"
586 >${sizeWithTokens(entry.size, target)}</span
589 >${all ? fileSize(entry.size) : sizeWithTokens(entry.size, target)}</span
587590 >`
588591 : html``,
589592 nav: true,
@@ -591,7 +594,15 @@ export function treeListing(
591594 }),
592595 );
593596 }
594 if (hidden > 0) {
597 if (hidden > 0 && all) {
598 rows.push(

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.

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) {
595606 rows.push(
596607 row({
597608 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";
1111 import { createUser } from "../src/core/users.ts";
1212 import { getRepo } from "../src/core/repos.ts";
1313 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";
1416 import { treeListing } from "../src/web/pages/repo.ts";
1517 import { proveAll } from "./helpers/verified.ts";
1618 import { quietLogs } from "./helpers/globals.ts";
@@ -54,6 +56,41 @@ describe("tree window", () => {
5456 });
5557 });
5658
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
5794 describe("through a request", () => {
5895 let root = "";
5996 let app: App;
@@ -79,14 +116,20 @@ describe("through a request", () => {
79116 });
80117 if (!made.ok) throw new Error(made.error);
81118 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 ];
86129 const done = await commitToBranch(app, u.value, repo!, { files });
87130 if (!done.ok) throw new Error(JSON.stringify(done.error));
88131 servers = await serve(app);
89 });
132 }, 60_000);
90133 afterAll(() => {
91134 servers.stop();
92135 app.close();
@@ -107,6 +150,18 @@ describe("through a request", () => {
107150 expect(page).toContain("case-1199.ts");
108151 expect(page).toContain("case-0300.ts");
109152 });
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 });
110165 test("the side column's lazy fragment is windowed too", async () => {
111166 const frag = await get("?fragment=explorer");
112167 expect(frag).toContain("case-0099.ts");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs