Repository navigation
Commit a354bb0
fix(app-shell): the inbox badge's receipt read no longer waits on the message read (#35519)
Fixes #35410
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:所有控制台用户打开任何页面时,铃铛角标的已读状态与收件箱消息同时读取,不再排在页面最后一批单独等待;角标数字与以前完全一样。
- 为什么做:页面加载分层工作的后续,替控制台每次开页省掉最后一层排队请求。
- 出错会怎样:已读状态取错时角标会多算或少算未读条数;直接撤回本次改动即可恢复。
- 要你做什么:无。
## What changes
The inbox feed behind the bell badge and Home's action centre
(`useSharedInboxFeed`) used to read the newest 20 `sys_inbox_message`
rows, wait for the answer, and only then read `sys_notification_receipt`
narrowed to the listed notification ids. On the showcase list page that
receipt read was the page's last request layer on every load.
Each tick now sends two reads at once:
- `sys_inbox_message`, `user_id`, newest first, top 20 (unchanged);
- `sys_notification_receipt`, `user_id` + `channel: 'inbox'`, newest
first, top 20: the same window over the receipts. The inbox channel
writes each message's `delivered` receipt right after the message, so in
the steady state this read carries exactly the listed messages'
receipts.
Only for a listed notification id that the parallel read did not carry
(a receipt written later than its delivery, or never written) does the
tick send the id-scoped read the card's ruling kept: `notification_id`
in the missing ids, top = their count. The answer stays exact: the
receipt's key `(notification_id, user_id, channel)` is unique, so a
listed id either has its one receipt in the parallel read or is asked
for by name. The unread count is unchanged: the badge folds the message
rows, and receipts only decorate them.
Kept as before: receipts unavailable means every listed message renders
unread (and no follow-up is sent); a 404 or `OBJECT_NOT_FOUND` on the
message read retires the poll; a key whose last window listed nothing
joinable sends no receipt read on its later ticks (the first tick of a
page load cannot know, so it sends the parallel read once).
Route chosen: (2) of the dispatch (parallel, bounded). Route (1) fails
without a server or spec change, measured live on the showcase backend:
- `$expand=notification_id` on `sys_inbox_message` answers `400
INVALID_FIELD` ("Field 'notification_id' on object 'sys_inbox_message'
is not a relationship"): both `notification_id` columns are text, so
there is no relation to expand or semi-join on.
- `GET /api/v1/notifications` is a server-side join, but its rows carry
no `actor_id`, no `receipt_id` and the notification id in place of the
inbox row id, all of which the feed's rows carry today; it also reads
every inbox receipt of the user, unbounded, on the server.
Receipt rows per tick: at most 20 (the window) plus the ids the window
read missed; the measured steady state on showcase is the id count (3 of
3).
## Tests
- `sharedInboxFeed.receiptScope-7392.test.tsx` (the receipt harness):
the fake now honours `$orderby` and every receipt carries the
`created_at` its message has. Existing cases restated for the parallel
shape; a new top-level `describe` for this card pins: the receipt read
is issued while the message read is still pending; the id-scoped
follow-up asks only for the missed id (top 1) and gets its read-state;
no receipts at all means all unread; a read, clicked or dismissed
receipt beside a delivered one wins in either order; receipts
unavailable means all unread with no follow-up; a missing inbox object
still retires the poll.
- `sharedInboxFeed.cadence-7249.test.tsx`: the empty-window pin is now
"the attach read only, none per tick"; the fake answers each listed
message's receipt so one receipt read per tick is still the whole join.
<details><summary>Readings (head f811047; the full app-shell run
started at a82668f, and the only later commit, f811047, rewords two
comments)</summary>
- `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/`
under the lock: VERDICT command-exit 0; Test Files 2333 passed, 1
skipped (2334); Tests 21856 passed, 9 skipped (21865).
- `pnpm --filter @object-ui/app-shell run type-check` (both the source
and the test tsconfig) under the lock: VERDICT command-exit 0, 0 errors.
- Ablation 1 (the parallel read), `scripts/ablation-replace.mjs`, anchor
`inboxJoinableHint?.key === key && !inboxJoinableHint.joinable` replaced
by `true` (never read in parallel, the old sequential shape): anchor 1
to 0, blob 09b38fd to b24b4ce5fe38; 9 failed, 13 passed, the new
layer pin among the failures; restored, blob equals HEAD, `git diff
HEAD` empty.
- Ablation 2 (the follow-up), anchor `missing.length === 0 ? []` made
unconditional: 2 failed (the missed-id pin and the shared-notification
pin), 20 passed; restored, blob equals HEAD.
- Source-resolved suites (relative imports into `src/`), so no dist leg.
</details>
## Acceptance notes
- Measurement environment: a fresh `objectstack dev` showcase backend on
its own port and the Console's Vite dev server pointed at it, admin
signed in, `/apps/com.example.showcase/showcase_task`, resource timings
of `/api/` requests on a warm module graph, three loads per side. The
Vite console sends 28 API requests here (the card counted 25 on the
built console); the count is the same before and after. A request's
layer is one more than the deepest request that had answered before it
started.
- Before (base 6f36818): the receipt read is alone in the last layer in
3 of 3 loads, started 188, 289 and 473 ms after the message read
answered. Chain depth 11, 12, 13.
- After: the receipt read starts with the message read (0 to 1 ms apart)
and shares its layer in 3 of 3 loads; no layer follows the inbox pair.
Chain depth 8, 11, 9 (the depth itself is noisy on a shared box; the
dependency is not).
- An empty inbox costs one receipt read on the page load (it cannot be
known empty before the message read answers) and none per later tick.
- A user whose listed messages hold no receipt at all (receipt write
failed) gets the id-scoped follow-up each tick, sequential as before and
exact.
- Database side: the parallel read orders the user's inbox receipts by
`created_at`; the object declares indexes on the unique key and on
`(user_id, state)`, none on `created_at`. The payload stays at 20 rows;
the receipts are transient (90 days).
## Verification
Read first: `useSharedInboxFeed` in
`ui/packages/app-shell/src/hooks/sharedUserFeeds.ts` (the two reads and
the follow-up), then the new `describe` in
`sharedInboxFeed.receiptScope-7392.test.tsx`.
Two-minute check: `pnpm --dir ui exec vitest run
packages/app-shell/src/hooks/__tests__/sharedInboxFeed.receiptScope-7392.test.tsx`
shows the "receipt read no longer waits on the message read" block
green.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d76d57a commit a354bb0
4 files changed
Lines changed: 391 additions & 114 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| |||
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
124 | 141 | | |
125 | 142 | | |
126 | 143 | | |
127 | 144 | | |
128 | 145 | | |
| 146 | + | |
129 | 147 | | |
130 | 148 | | |
131 | 149 | | |
| |||
220 | 238 | | |
221 | 239 | | |
222 | 240 | | |
223 | | - | |
| 241 | + | |
224 | 242 | | |
225 | 243 | | |
226 | 244 | | |
227 | | - | |
228 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
229 | 248 | | |
230 | 249 | | |
231 | 250 | | |
| |||
234 | 253 | | |
235 | 254 | | |
236 | 255 | | |
237 | | - | |
238 | | - | |
| 256 | + | |
| 257 | + | |
239 | 258 | | |
240 | 259 | | |
241 | 260 | | |
| |||
0 commit comments