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:
1 parent
e6be593542
commit
91596300e1
6 files changed
+251
-49
No files matched your search
+57
-2
@@ -388,13 +388,68 @@ class ExtractResult(ModelTaskResult):
|
||||
|
||||
|
||||
class ScoredRole(Role):
|
||||
"""A role as `/api/roles` serves it: with one agent's score and gate
|
||||
reason when an agent was asked for, and without otherwise."""
|
||||
"""A role as `/api/roles/{uid}` serves it: with one agent's score and
|
||||
gate reason when an agent was asked for, and without otherwise."""
|
||||
|
||||
score: float | None = None
|
||||
gated_reason: str = ""
|
||||
|
||||
|
||||
#: How many characters `RoleRow.excerpt` keeps at most: the feed row's own
|
||||
#: cap, built once here rather than by the client, so a list response never
|
||||
#: carries more of a role's text than a row draws.
|
||||
EXCERPT_LIMIT = 200
|
||||
|
||||
|
||||
def excerpt(text: str, limit: int = EXCERPT_LIMIT) -> str:
|
||||
"""`text` (a role's summary, or the opening of its description) with its
|
||||
whitespace collapsed, cut to `limit` characters at a word boundary with
|
||||
an ellipsis. What `Store.roles_page` builds `RoleRow.excerpt` with, off a
|
||||
`SUBSTR` of the source column rather than the whole of it, so the feed's
|
||||
list never carries what only the reader needs."""
|
||||
collapsed = " ".join((text or "").split())
|
||||
if len(collapsed) <= limit:
|
||||
return collapsed
|
||||
cut = collapsed[:limit]
|
||||
space = cut.rfind(" ")
|
||||
trimmed = cut[:space] if space > limit * 0.6 else cut
|
||||
return trimmed.rstrip(" ,.;:" + chr(0x2013) + "-") + "…"
|
||||
|
||||
|
||||
class RoleRow(Model):
|
||||
"""One row of the feed: what `GET /api/roles` serves per role, the
|
||||
fields a row draws and nothing else — never `description`, `feed_text`,
|
||||
`raw` or `article_text`, the four columns docs/decisions.md measures at
|
||||
about 5.5 KB a role between them. The reader fetches the rest by uid when
|
||||
it opens a role (`GET /api/roles/{uid}`, the full `Role`).
|
||||
|
||||
`excerpt` is built on the server (see `excerpt`, above): the summary when
|
||||
there is one, else the description's opening, cut to `EXCERPT_LIMIT`
|
||||
characters. `salary_min`, `salary_max` and `currency` are the pay fields
|
||||
a row already draws; `salary_text` and `salary_state`, once the role
|
||||
model carries them, belong here too."""
|
||||
|
||||
uid: str
|
||||
company_key: str = ""
|
||||
company: str = ""
|
||||
title: str = ""
|
||||
place: str = ""
|
||||
country: str = ""
|
||||
remote: Remote = ""
|
||||
function: str = ""
|
||||
salary_min: int | None = None
|
||||
salary_max: int | None = None
|
||||
currency: str = ""
|
||||
posted_at: str = ""
|
||||
score: float | None = None
|
||||
gated_reason: str = ""
|
||||
vote: Literal[-1, 0, 1] | None = None
|
||||
voted_at: str | None = None
|
||||
read_at: str | None = None
|
||||
tags: list[str] = []
|
||||
excerpt: str = ""
|
||||
|
||||
|
||||
class Company(Model):
|
||||
"""A row of `companies`, with `affinity` as the agent it was read for
|
||||
has it (see `agent_companies`); 0 when no agent was asked for."""
|
||||
|
||||
Reference in new issue
Block a user