Skip to content

perf(conversations): Read the feed in three rounds - #3820

Merged
BYK merged 3 commits into
mainfrom
perf/feed-rounds
Nov 19, 2026
Merged

BYK merged 3 commits into
mainfrom
perf/feed-rounds

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GET /api/conversations waited on reads that did not depend on each other. On the heavy feed seed from #3809 (include=links,media), it ran 23 statements in 7 serial rounds. It now runs 21 statements in 3 rounds. The response stays the same.

  • Waiting rows: the first page read the waiting ids, then the rows for the ids outside the page. Now a third row read in the first round filters by waitingConversationIdsQuery as a subquery, and the feed dedupes it in JS against the pins and the page. listWaitingConversations and the subquery share one root expression.
  • Threads: readFeedThreads waited on access before it read anything. readFeedThreadRecords now reads the Thread rows, trees and the first messages of untitled Threads in the main batch, and nestFeedThreads applies access afterwards.
  • Slack tenants: attachActivityPreviewMentions read each conversation's tenant again. The feed now takes it from the rows it already has, through conversationSlackTenantId, which loadConversationSlackTenantIds also uses. The detail route keeps its lookup.

Mention resolution and sidebar annotations now run together after the batch.

Heavy seed Statements Rounds
Before 23 7
After 21 3

On the same seed with preview mentions and an untitled Thread, the request goes from 25 statements in 9 rounds to 23 in 5.

The serialRounds budgets on the feed scenarios go down to match: list-brief 3 → 2, list-answer 5 → 3, tree-state feed 5 → 3. The statement budgets do not change.

The heavy viewer's feed in list-budget.test.ts now also has an expectSqlBudget of 21 statements and 3 serial rounds.

via @BYK.

--

View Session [Sentry]

Start the waiting rows, the Thread records and the Slack tenants with the
reads they do not depend on:

- Read the waiting rows in the first round, with the waiting ids as a
  subquery of the row read.
- Read the Thread records in the main batch and nest them after access.
- Take the Slack tenant of each preview from the feed rows.

Co-Authored-By: BYK <[email protected]>
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 19, 2026 7:26pm UTC

Request Review

# Conflicts:
#	packages/junior/src/api/conversations/list.ts
The heavy feed reads in 21 statements and 3 serial rounds.
@BYK
BYK merged commit ebe0748 into main Nov 19, 2026
52 checks passed
@BYK
BYK deleted the perf/feed-rounds branch November 19, 2026 22:04
BYK added a commit that referenced this pull request Nov 19, 2026
`GET /api/conversations` read some rows twice. On the heavy feed seed
from #3809 (`include=links,media`), it ran 23 statements. It now runs
20. The response stays the same.

- **Participants:** access read the viewer's participant rows, and the
pin marks read the same rows again with `pinned_at is not null`. The
feed now reads them once with `readMemberParticipants` and passes the
roots to `conversationAccessFromRows`. `readConversationAccessFromSql`
is now `readConversationAccessRows` plus that projection, so its other
callers do not change. Feed rows are roots, so these roots cover the
access check. An actor email feed with no viewer still reads only its
pin marks.
- **Avatars:** `readConversationParticipants` and
`readConversationAuthors` read user photos in a second statement. Both
participant reads now join the photo Identities with `hasUserPhoto`.
`userAvatarUrlsFromJoinedPhotos` picks the photo, and
`readMentionedPeople` uses it too.
- **Children:** `listConversationWork` and `readFeedThreads` each read
the children of the same roots. The feed reads `readConversationTrees`
once and passes it to both. `ConversationTreeNode` now carries
`rootConversationId` for the work owners. Other `listConversationWork`
callers read the tree themselves.

| Heavy seed | Statements | Rounds |
| --- | --- | --- |
| Before | 23 | 7 |
| After | 20 | 7 |

The rounds do not change here. #3820 removes them. On
the same seed with preview mentions and an untitled Thread, the request
goes from 25 statements to 22.

The SQL budgets go down to match: `list-brief` 15 → 14 statements,
`list-answer` 19/5 → 17/4, `tree-state` feed 20/5 → 17/4 and detail 20 →
19 statements.

This PR and #3820 both change
`readConversationFeedFromSql`. The one that merges second merges `main`
in and keeps both changes.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A2c3e432e56cd1bf6d0fbfabed08dc476 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — b3d79829 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant