Public: anyone can read this; the crew can change it.

An app's explore row shows its last-ship date and fork count read from stored state, with no per-row query #13697

Merged opened this

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

Merged

scout/forge:scout/13680-an-app-s-explore-row-shows-its-last-ship → main 4 commits fork

  • Merged. scout/13680-an-app-s-explore-row-shows-its-last-ship was merged into main as 0644f5b.

Review

Sign in to review this change.
5 files changed +82 −17
src/actions/explore.ts +13 −5
@@ -345,14 +345,22 @@ export function exploreLine(query: ExploreQuery): string {
345345
346346 const plural = (n: number, one: string, many: string): string => `${n} ${n === 1 ? one : many}`;
347347
348 /**
349 * When a row last shipped, in words ("today", "yesterday", "3 days ago") on the caller's one clock.
350 */
351 export function shippedAgo(shippedAt: string, now: number): string {
352 const days = Math.floor((now - Date.parse(shippedAt)) / 86_400_000);
353 if (!Number.isFinite(days)) return "";
354 if (days < 1) return "today";
355 if (days === 1) return "yesterday";
356 return `${days} days ago`;
357 }
358
348359 /** How long ago a row last shipped, in words; "" when it never did. */
349360 function shippedWords(shippedAt: string | null, now: number): string {
350361 if (shippedAt === null) return "";
351 const days = Math.floor((now - Date.parse(shippedAt)) / 86_400_000);
352 if (!Number.isFinite(days)) return "";
353 if (days < 1) return "shipped today";
354 if (days === 1) return "shipped yesterday";
355 return `shipped ${days} days ago`;
362 const ago = shippedAgo(shippedAt, now);
363 return ago === "" ? "" : `shipped ${ago}`;
356364 }
357365
358366 /**
src/web/studio/explore.ts +2 −1
@@ -16,6 +16,7 @@ import {
1616 exploreNote,
1717 exploreSuggestion,
1818 MAKE_IT_YOURS,
19 shippedAgo,
1920 whyOf,
2021 figureCounts,
2122 readExploreLine,
@@ -42,7 +43,7 @@ function rowHtml(row: ExploreRow, signedIn: boolean, query: ExploreQuery, now: n
4243 // One row: what it does in plain words, then the one signal that explains its place.
4344 // Apps say their counts and keep the dated `<time>`: the absolute date stays in its title.
4445 const figures = figureCounts(row, query.sort);
45 const signal = figures !== "" ? (row.shippedAt === null ? html`${figures}, never shipped` : html`${figures}, shipped ${time(row.shippedAt)}`) : why === undefined ? "" : why.signal === "fresh" && row.shippedAt !== null ? html`shipped ${time(row.shippedAt)}` : html`${why.text}`;
46 const signal = figures !== "" ? (row.shippedAt === null ? html`${figures}, never shipped` : html`${figures}, shipped ${time(row.shippedAt, { text: shippedAgo(row.shippedAt, now) })}`) : why === undefined ? "" : why.signal === "fresh" && row.shippedAt !== null ? html`shipped ${time(row.shippedAt, { text: shippedAgo(row.shippedAt, now) })}` : html`${why.text}`;
4647 // One tap from a person to their apps; with none, the count is plain text.
4748 const theirs = href({ kind: "app", sort: "score", text: "", archived: false, updated: "all", owner: row.name });
4849 const apps = row.kind === "person" ? `${row.numbers.apps} app${row.numbers.apps === 1 ? "" : "s"}` : "";
src/web/ui.ts +22 −9
@@ -55,13 +55,13 @@ export function timeAgo(iso: string): string {
5555 * `date` words it as the calendar day (`2026-12-02`), for an instant ahead
5656 * of now, which "ago" cannot name.
5757 */
58 export function time(iso: string, opts: { date?: boolean } = {}): Html {
58 export function time(iso: string, opts: { date?: boolean; text?: string } = {}): Html {
5959 const parsed = Date.parse(iso);
6060 if (Number.isNaN(parsed)) return html``;
6161 const at = new Date(parsed);
6262 const exact = `${at.toISOString().slice(0, 16).replace("T", " ")} UTC`;
6363 return html`<time datetime="${at.toISOString()}" title="${exact}"
64 >${opts.date === true ? at.toISOString().slice(0, 10) : timeAgo(iso)}</time
64 >${opts.text ?? (opts.date === true ? at.toISOString().slice(0, 10) : timeAgo(iso))}</time
6565 >`;
6666 }
6767
@@ -185,7 +185,10 @@ export interface BtnOptions {
185185 extra?: string;
186186 /** The element's id, for a script or a fragment link that finds it. */
187187 id?: string;
188 /** A pager's link says which way it goes (`rel="next"`): a reader of the list follows it (`bind.ts`). */
188 /**
189 * A pager's link says which way it goes (`rel="next"`): a reader of the list follows it
190 * (`bind.ts`).
191 */
189192 rel?: "next" | "prev";
190193 }
191194
@@ -712,7 +715,9 @@ export function repoCounts(o: {
712715 openPulls?: number | null | undefined;
713716 /** Some origins report one number for issues *and* pulls; say so. */
714717 issuesIncludePulls?: boolean;
715 /** The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers. */
718 /**
719 * The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers.
720 */
716721 of?: { ownerName: string; name: string } | undefined;
717722 }): Html {
718723 const issues = o.openIssues ?? null;
@@ -777,7 +782,9 @@ export function chartBox(chart: Chart, cells: readonly Cell[], title: string): H
777782 return chartFrame(chart, drawChart(chart, cells, title));
778783 }
779784
780 /** The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows). */
785 /**
786 * The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows).
787 */
781788 export function chartFrame(chart: Chart, drawn: string): Html {
782789 return html`<div class="chart-box${chart === "table" ? " is-table" : ""}">${raw(drawn)}</div>`;
783790 }
@@ -971,8 +978,9 @@ export interface RowOptions {
971978 href?: string;
972979 title: Html | string;
973980 meta?: Html;
974 /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts the row's
975 * main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose `<summary>` takes phrasing only. */
981 /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts
982 * the row's main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose
983 * `<summary>` takes phrasing only. */
976984 facts?: readonly { label: string; value: Html | string }[];
977985 /** Draw `.row-meta` even when `meta` is empty, for a script to write into. */
978986 metaSlot?: boolean;
@@ -997,7 +1005,9 @@ export interface RowOptions {
9971005 /** The row folds: it is the `<summary>` of a `<details>` holding `body`,
9981006 * open when `open` says so. Its `lead` is the caret. */
9991007 fold?: { id: string; open: boolean; body: Html };
1000 /** Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report. */
1008 /**
1009 * Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report.
1010 */
10011011 apart?: string | undefined;
10021012 /** The row is a node of an ARIA tree: the row itself is the `treeitem` (it is what takes focus,
10031013 * so it says its level and, for a branch, `aria-expanded`), its `<li>` is `role="none"`,
@@ -1092,7 +1102,10 @@ export function tabs(items: TabItem[], ariaLabel: string): Html {
10921102 /** A segmented control built from links (a GET filter is navigation). */
10931103 export function seg(
10941104 items: { label: string; href: string; current: boolean; count?: number }[],
1095 /** These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`, `bind.ts`). */
1105 /**
1106 * These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`,
1107 * `bind.ts`).
1108 */
10961109 filters = false,
10971110 ): Html {
10981111 return html`<div class="seg"${filters ? raw(" data-rows-tabs") : null}>
test/explore-metrics.test.ts added +43
@@ -0,0 +1,43 @@
1 /**
2 * An explore row's freshness and fork count come from batched reads: the statements do not grow
3 * with the rows (#13680).
4 */
5 import { expect, test } from "bun:test";
6 import { snappyFixture } from "../bench/snappy.ts";
7 import { explore, parseExploreQuery, shippedAgo } from "../src/actions/explore.ts";
8 import { createApp as insertApp } from "../src/core/apps.ts";
9
10 async function statementsFor(repos: number): Promise<{ statements: number; rows: number }> {
11 const f = await snappyFixture({ repos, issuesPerRepo: 0 });
12 try {
13 for (const repo of f.repos) {
14 const made = insertApp(f.app.db, { repoId: repo.id, slug: `${repo.ownerName}-${repo.name}`, access: "public" });
15 if (!made.ok) throw new Error(made.error);
16 }
17 // Passing a clock skips the kept ranking, so every row is read for real.
18 const query = parseExploreQuery("kind:app sort:fresh");
19 await explore(f.app, undefined, query, Date.now());
20 f.counter.reset();
21 const rows = await explore(f.app, undefined, query, Date.now());
22 return { statements: f.counter.count, rows: rows.length };
23 } finally {
24 await f.close();
25 }
26 }
27
28 test("a full page of rows costs the same number of statements as a few", async () => {
29 const small = await statementsFor(6);
30 const large = await statementsFor(30);
31 // The fixture makes every third repository public, so 6 repositories show 2 rows and 30 show 10:
32 // the statements must not grow with the rows.
33 expect(small.rows).toBe(2);
34 expect(large.rows).toBe(10);
35 expect(large.statements).toBe(small.statements);
36 }, 120_000);
37
38 test("the last ship is told in days on the caller's clock", () => {
39 const now = Date.parse("2026-11-15T12:00:00Z");
40 expect(shippedAgo("2026-11-12T11:00:00Z", now)).toBe("3 days ago");
41 expect(shippedAgo("2026-11-14T11:00:00Z", now)).toBe("yesterday");
42 expect(shippedAgo("2026-11-15T01:00:00Z", now)).toBe("today");
43 });
test/explore-parity.test.ts +2 −2
@@ -323,9 +323,9 @@ describe("separate parameters", () => {
323323 });
324324
325325 describe("last ship on the row", () => {
326 test("the page words it as shipped 1d ago with the absolute date in title; the API carries shippedAt", async () => {
326 test("the page words it as shipped yesterday with the absolute date in title; the API carries shippedAt", async () => {
327327 const html = await (await fetch(`${servers.url}/explore?q=${encodeURIComponent("kind:app sort:fresh")}`)).text();
328 expect(html).toMatch(/shipped <time datetime="[^"]+" title="\d{4}-\d\d-\d\d \d\d:\d\d UTC"\s*>1d ago<\/time/);
328 expect(html).toMatch(/shipped <time datetime="[^"]+" title="\d{4}-\d\d-\d\d \d\d:\d\d UTC"\s*>yesterday<\/time/);
329329 const api = (await (await fetch(`${servers.url}/api/v1/explore?q=${encodeURIComponent("kind:app sort:fresh")}`)).json()) as { items: { name: string; shippedAt: string | null }[] };
330330 expect(api.items[0]!.shippedAt).not.toBeNull();
331331 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs