Skip to content

Commit a354bb0

Browse files
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

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the inbox badge's read-state no longer waits for the inbox messages to load
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The bell badge and Home's action centre read the signed-in user's newest 20 inbox messages and the receipts that say which of them are read. The receipt read used to start only after the message read answered, so on every console page load it was the last request to go out. It now reads the newest 20 inbox receipts at the same time as the newest 20 messages, and asks by id only for a listed message whose receipt that read did not carry, so the read-state, the unread count and the badge stay exactly as they were. An inbox with no messages still sends no receipt read on its later polls.

‎ui/packages/app-shell/src/hooks/__tests__/sharedInboxFeed.cadence-7249.test.tsx‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@
7979
* read is due. The equality is unchanged; what changed is that it is now
8080
* exercised on a window that has something to join, with the empty window
8181
* pinned separately below.
82+
*
83+
* objectstack#35410 then moved the receipt read beside the message read (the
84+
* newest receipts, in parallel), keeping the id-scoped read for listed ids
85+
* that read missed. The fake below therefore answers each listed message's
86+
* receipt, so one receipt read per tick is still the whole join; and an empty
87+
* window still costs no receipt read per tick — only the attach read, which
88+
* cannot know the window is empty before it answers.
8289
*/
8390
import '@testing-library/jest-dom/vitest';
8491
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
@@ -121,11 +128,22 @@ const INBOX_ROWS: Array<Record<string, unknown>> = [
121128
/** What the fake inbox answers with — emptied by the case that pins that path. */
122129
let inboxRows: Array<Record<string, unknown>> = INBOX_ROWS;
123130

131+
/** One `delivered` receipt per fixture message, written with it (ADR-0030). */
132+
const RECEIPT_ROWS: Array<Record<string, unknown>> = INBOX_ROWS.map((m, i) => ({
133+
id: `rcp_${i + 1}`,
134+
notification_id: m.notification_id,
135+
user_id: 'u1',
136+
channel: 'inbox',
137+
state: 'delivered',
138+
created_at: m.created_at,
139+
}));
140+
124141
const findCalls: Array<{ object: string }> = [];
125142
const fakeAdapter = {
126143
find: (object: string) => {
127144
findCalls.push({ object });
128145
if (object === 'sys_inbox_message') return Promise.resolve({ data: inboxRows });
146+
if (object === 'sys_notification_receipt') return Promise.resolve({ data: RECEIPT_ROWS });
129147
return Promise.resolve({ data: [] });
130148
},
131149
// objectui#13044 — the real MetadataProvider reads an object by name through
@@ -220,12 +238,13 @@ describe('objectui#7249 — the inbox feed holds ONE declared cadence', () => {
220238
expect(receiptReads()).toBe(inboxReads());
221239
});
222240

223-
it('issues NO receipt read on a window with nothing to join (objectui#7392)', async () => {
241+
it('issues NO receipt read per tick on a window with nothing to join (objectui#7392)', async () => {
224242
// The other half of the equality above. The receipt read exists to decorate
225243
// the listed messages with read-state; with no messages listed there is
226244
// nothing it could decorate, and every row it would return is one
227-
// `mergeInboxRows` drops. So the correct count here is zero, per tick,
228-
// forever — not "as frequent as the message read".
245+
// `mergeInboxRows` drops. So the correct count per tick is zero, forever —
246+
// not "as frequent as the message read". The attach read alone goes out,
247+
// beside the message read, before either has answered (objectstack#35410).
229248
inboxRows = [];
230249

231250
renderHook(() => useSharedInboxFeed());
@@ -234,8 +253,8 @@ describe('objectui#7249 — the inbox feed holds ONE declared cadence', () => {
234253

235254
// Same window, same cadence — the message read is untouched …
236255
expect(inboxReads()).toBe(READS_IN_WINDOW);
237-
// … and not one receipt read went out behind it.
238-
expect(receiptReads()).toBe(0);
256+
// … and not one receipt read went out behind it: the attach read only.
257+
expect(receiptReads()).toBe(1);
239258
});
240259

241260
it('is one FEED cadence, not one per consumer', async () => {

0 commit comments

Comments
 (0)