Public: anyone can read this; the crew can change it.
People, the Closed list and Activity answer in under 50 ms with 200 deals, and the speed test proves it #228
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/224-people-the-closed-list-and-activity-answ → main 1 commit fork
2 files
changed +25
−3
src/people.ts +4 −2
| @@ -75,12 +75,14 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 75 | 75 | for (const deal of deals) { |
| 76 | 76 | for (const party of deal.parties) { |
| 77 | 77 | const keys = personKeys(party); |
| 78 | let one: One = { name: party.name, newest: -1, contact: party.contact.trim(), email: party.email.trim(), phone: party.phone.trim(), roles: new Set(), owes: new Map(), last: null }; | |
| 78 | const fresh: One = { name: party.name, newest: -1, contact: party.contact.trim(), email: party.email.trim(), phone: party.phone.trim(), roles: new Set(), owes: new Map(), last: null }; | |
| 79 | let one = fresh; | |
| 79 | 80 | for (const key of keys) { |
| 80 | 81 | const found = byKey.get(key); |
| 81 | 82 | if (found !== undefined && found !== one) { |
| 82 | 83 | merge(found, one); |
| 83 | for (const [k, v] of byKey) if (v === one) byKey.set(k, found); | |
| 84 | // A fresh row holds no key yet, so only a person already found needs its keys repointed. | |
| 85 | if (one !== fresh) for (const [k, v] of byKey) if (v === one) byKey.set(k, found); | |
| 84 | 86 | one = found; |
| 85 | 87 | } |
| 86 | 88 | } |
src/speed.test.ts +21 −1
| @@ -19,6 +19,7 @@ let movable = 0; | ||
| 19 | 19 | let server: ReturnType<typeof serve>; |
| 20 | 20 | let base = ""; |
| 21 | 21 | let headers: Record<string, string> = {}; |
| 22 | let adminHeaders: Record<string, string> = {}; | |
| 22 | 23 | |
| 23 | 24 | // Seeded when this file's tests start, not when the file is loaded: the |
| 24 | 25 | // writes would otherwise reach other files' servers mid-test. |
| @@ -39,6 +40,19 @@ beforeAll(() => { | ||
| 39 | 40 | // The buyer and seller are in; a lender and a title company make four. |
| 40 | 41 | const lender = party.get(deal.id, "lender", `Lender ${i}`, "[email protected]") as { id: number }; |
| 41 | 42 | party.get(deal.id, "title", `Title ${i}`, "[email protected]"); |
| 43 | // Every fifth deal has closed, and a third have a message sent to the | |
| 44 | // lender, so People, the Closed list and Activity have rows to render. | |
| 45 | if (i % 5 === 4 && i > 4) | |
| 46 | seeded.query("UPDATE deadline SET done_at = '2026-11-03T15:00:00.000Z' WHERE deal_id = ?1 AND kind = 'closing'").run(deal.id); | |
| 47 | if (i % 3 === 1) { | |
| 48 | const [only] = seeded.query<{ id: number; label: string; due: string }, [number]>("SELECT id, label, due FROM deadline WHERE deal_id = ?1 ORDER BY due, id").all(deal.id); | |
| 49 | seeded | |
| 50 | .query("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, party_role, moment, due, by_name, subject, body) VALUES (?1, ?2, ?3, ?4, ?5, 'lender', 'day_of', ?6, 'alice', 'Reminder', 'Hello')") | |
| 51 | .run(deal.id, only!.id, lender.id, only!.label, `Lender ${i}`, only!.due); | |
| 52 | seeded | |
| 53 | .query("INSERT INTO audit (who_id, who_name, role, resource, verb, target, allowed, outcome, what) VALUES ('u1','alice','user','deal','update',?1,1,'ok','reminder.send')") | |
| 54 | .run(String(deal.id)); | |
| 55 | } | |
| 42 | 56 | if (i % 2 !== 0) continue; |
| 43 | 57 | const [first, second] = seeded |
| 44 | 58 | .query<{ id: number; label: string; due: string }, [number]>("SELECT id, label, due FROM deadline WHERE deal_id = ?1 ORDER BY due, id") |
| @@ -59,6 +73,8 @@ beforeAll(() => { | ||
| 59 | 73 | base = `http://${server.hostname}:${server.port}`; |
| 60 | 74 | const identity = `u1|alice|user|${Date.now() + 600_000}`; |
| 61 | 75 | headers = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; |
| 76 | const boss = `a1|admin|admin|${Date.now() + 600_000}`; | |
| 77 | adminHeaders = { "x-forge-identity": boss, "x-forge-signature": sign(boss, KEY) }; | |
| 62 | 78 | }); |
| 63 | 79 | afterAll(() => server.stop(true)); |
| 64 | 80 | beforeEach(forgetRationing); |
| @@ -69,7 +85,7 @@ const mid = (times: number[]): number => times.sort((x, y) => x - y)[Math.floor( | ||
| 69 | 85 | /** Ms from sending a request to the response head: the app has built and compressed the page by then. */ |
| 70 | 86 | async function timed(path: string): Promise<number> { |
| 71 | 87 | const start = performance.now(); |
| 72 | const res = await fetch(base + path, { headers }); | |
| 88 | const res = await fetch(base + path, { headers: path === "/activity" ? adminHeaders : headers }); | |
| 73 | 89 | const took = performance.now() - start; |
| 74 | 90 | expect(res.status).toBe(200); |
| 75 | 91 | // The body is read after the clock stops, so the budget is the app's, not |
| @@ -113,6 +129,10 @@ const routes: [string, () => string][] = [ | ||
| 113 | 129 | ["the broker file", () => `/deals/${firstId}/file`], |
| 114 | 130 | ["the printed week", () => "/week"], |
| 115 | 131 | ["the reminder review", () => "/reminders/today"], |
| 132 | ["people", () => "/people"], | |
| 133 | // The Closed list is the clock's lower section: the fixture closes some deals. | |
| 134 | ["the clock with closed deals", () => "/?closed=1"], | |
| 135 | ["activity (as admin)", () => "/activity"], | |
| 116 | 136 | ]; |
| 117 | 137 | |
| 118 | 138 | test.each(routes)("%s answers in under 50 ms with 200 deals", async (_name, path) => { |
new above
offline