Serve a row projection from GET /api/roles instead of the whole role

The feed only ever shows a title, a few badges and a short excerpt,
but the list endpoint answered with every role's full row --
description, feed_text, raw and article_text included, about 5.5 KB
a role -- so a 1000-row restore was several megabytes of text a phone
never renders.

Store.roles_page selects only the fields a row draws (RoleRow), with
excerpt built server-side off a SUBSTR of summary or description, so
the big columns never cross into the response. The reader is
unaffected: it already fetched the whole role by uid when it opened
one; the reader pane's own reliance on the list row carrying the body
is removed too, so it no longer flashes a wrong "no description"
before that fetch lands.

Measured on a copy of the live database: a 60-row page went from
392 KiB to 39 KiB, and a 1000-row restore from 6.6 MB to 631 KiB.

Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet committed 2026-09-29 15:22:00 +02:00
1 parent e6be593542
commit 91596300e1
6 files changed
+251 -49

No files matched your search

+26 -14
View File
@@ -473,15 +473,23 @@
for (const el of had.values()) el.remove();
}
/* The summary when there is one, else the description's opening, cut at a
word. */
/* Built on the server (`app.models.excerpt`) and served as `role.excerpt`,
so the list response never carries the full description a row would
otherwise need to cut this from — see docs/decisions.md, "The pages". */
function excerpt(role) {
if (role.summary) return role.summary;
const text = (role.description || "").replace(/\s+/g, " ").trim();
if (text.length <= 160) return text;
const cut = text.slice(0, 160);
return role.excerpt || "";
}
/* The same cut, run here instead: for the one row `merge` refreshes after
a fetch or a summarise, off the full role that call answers with, which
is the only time this page ever sees a role's `summary` or
`description` directly. */
function excerptOf(role) {
const text = (role.summary || role.description || "").replace(/\s+/g, " ").trim();
if (text.length <= 200) return text;
const cut = text.slice(0, 200);
const space = cut.lastIndexOf(" ");
return `${(space > 100 ? cut.slice(0, space) : cut).replace(/[\s,.;:–-]+$/, "")}…`;
return `${(space > 120 ? cut.slice(0, space) : cut).replace(/[\s,.;:–-]+$/, "")}…`;
}
function tagChips(tags) {
@@ -723,9 +731,13 @@
}
if (!open) { el.replaceChildren(); return; }
// The list row is already in memory, and a list row is the whole role, so
// the pane paints from it at once and the fetch only brings it up to date.
// The list row is already in memory, and carries what a row draws —
// title, company, place, tags, pay — so the pane paints those at once;
// the body, the summary state and the original link wait on the fetch
// (`loaded`), since the list row no longer carries them (see
// `Store.roles_page`).
const stub = state.items.find((r) => r.uid === state.readingUid);
const loaded = Boolean(state.reading) && state.reading.uid === state.readingUid;
const r = state.reading || stub || {};
const same = el.dataset.uid === state.readingUid;
const scrolled = same ? el.querySelector(".reader-body")?.scrollTop || 0 : 0;
@@ -736,13 +748,13 @@
const text = (r.article_text || r.description || "").trim();
const body = error
? `<p class="reader-note">This role could not be loaded: ${esc(error)}</p>`
: !r.uid
: !loaded
? `<p class="reader-note">Loading…</p>`
: text ? paragraphs(text)
: `<p class="reader-note">The board gave no description for this one.</p>`;
const pay = salary(r);
const waiting = state.summarising === state.readingUid;
const teaser = r.uid && !r.article_text && out && (r.description || "").length < TEASER;
const teaser = loaded && !r.article_text && out && (r.description || "").length < TEASER;
el.innerHTML = `
<div class="reader-bar">
@@ -767,7 +779,7 @@
${r.summary ? `<section class="reader-summary">
<h2 class="reader-label">Summary</h2><p>${esc(r.summary)}</p></section>` : ""}
<div class="reader-tools">
${r.uid && !r.summary && !waiting
${loaded && !r.summary && !waiting
? `<button type="button" class="secondary" data-tool="summarise">Summarise</button>` : ""}
${teaser ? `<button type="button" class="secondary" data-tool="fetch">Fetch the posting</button>` : ""}
<span class="muted small" role="status">${waiting
@@ -819,9 +831,9 @@
else state.reading = updated;
const item = state.items.find((x) => x.uid === updated.uid);
if (item) {
Object.assign(item, { summary: updated.summary, article_text: updated.article_text });
item.excerpt = excerptOf(updated);
const row = $(`#roles-list .row[data-uid="${CSS.escape(updated.uid)}"]`);
if (row) row.role = null; // drawn again from the new text
if (row) row.role = null; // drawn again from the new excerpt
renderFeed();
}
renderReader();