From 6d52af4b98c20ff88d9263e51c44f97151dc4ca4 Mon Sep 17 00:00:00 2001 From: zheng020 Date: Fri, 15 May 2026 11:29:04 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BF=AE=E5=A4=8D=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E8=AE=A1=E6=96=87=E6=A1=A3=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复内容: - 修正章节编号 8.2 -> 8.3 - 查询逻辑增加 star_id 条件 - HTTP 接口说明增加 star_id 传递方式 Co-Authored-By: Claude Opus 4.7 --- docs/specs/2026-05-15-notification-system-design.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/specs/2026-05-15-notification-system-design.md b/docs/specs/2026-05-15-notification-system-design.md index 9169b68..46a19d5 100644 --- a/docs/specs/2026-05-15-notification-system-design.md +++ b/docs/specs/2026-05-15-notification-system-design.md @@ -164,6 +164,8 @@ CREATE TABLE notification_stats ( | POST | /api/v1/notifications/read-all | 全部标已读 | | DELETE | /api/v1/notifications/:id | 删除通知 | +> **说明**:所有 HTTP 接口都需要通过 Header 或 Cookie 传递 `star_id` 进行数据隔离。 + ### 4.3 查询参数 ``` @@ -174,6 +176,7 @@ GET /api/v1/notifications?type=like&tab=today&page=1&pageSize=20 - tab: 查询tab (today / history) - page: 页码 - pageSize: 每页数量 +- star_id: 数据隔离 ID(从 Header 或上下文获取) ``` --- @@ -198,14 +201,16 @@ GET /api/v1/notifications?type=like&tab=today&page=1&pageSize=20 ``` 今日 Tab: - WHERE type = 'like' AND user_id = ? AND created_at >= 今日零点 + WHERE type = 'like' AND user_id = ? AND star_id = ? AND created_at >= 今日零点 ORDER BY created_at DESC 历史 Tab: - WHERE type = 'like' AND user_id = ? AND created_at < 今日零点 + WHERE type = 'like' AND user_id = ? AND star_id = ? AND created_at < 今日零点 ORDER BY created_at DESC ``` +> **说明**:所有查询都需要 `star_id` 确保数据隔离。 + ### 5.3 未读数统计 - 每次创建通知时,在同一事务中更新 `notification_stats` 表对应类型的未读数 @@ -291,7 +296,7 @@ ON notifications (user_id, star_id, type, data->>'target_id', data->>'actor_id', > **说明**:如果业务上允许同一天多条点赞通知(每条都展示),则不需要此唯一约束。 -### 8.2 补偿机制 +### 8.3 补偿机制 如果事务提交后 RPC 调用方未收到响应,调用方会重试。此时: - 使用唯一约束 `UNIQUE (user_id, star_id, type, target_type, target_id, actor_id, date)` 防止重复创建点赞通知