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

+9 -4
View File
@@ -16,7 +16,7 @@ from pydantic import BaseModel, Field
from app import jobs
from app.models import (
AFFINITY, Agent, Application, Company, Gate, Limits, Role, ScoredRole, Status,
AFFINITY, Agent, Application, Company, Gate, Limits, Role, RoleRow, Status,
Subscription, Weights, company_key,
)
from app.storage import Store
@@ -111,9 +111,14 @@ def unread_role(uid: str, store: StoreDep) -> Role:
class RolesPage(BaseModel):
"""One page of roles, and how many the same filters match in all."""
"""One page of roles, and how many the same filters match in all. `items`
is `RoleRow`, not the full `Role`: the fields a feed row draws, with an
excerpt built on the server, never the big columns (`description`,
`feed_text`, `raw`, `article_text`) a full role carries — see
`Store.roles_page`. The reader fetches the rest by uid when it opens one,
`GET /api/roles/{uid}`."""
items: list[ScoredRole]
items: list[RoleRow]
total: int
@@ -161,7 +166,7 @@ def list_roles(
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
"tag_mode": tag_mode, "agent": agent_id, "by_score": by_score,
"gated": gated, "judged": judged or None}
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
return RolesPage(items=store.roles_page(limit=limit, offset=offset, **filters),
total=store.count_roles(**filters))