Commit 700594d
committed
fix(server): cap task_actions / messages fetches at 500 rows
Every SSE reconnect on a task was reading every row in task_actions
and messages for that task, then slicing to 50 in JS. D1 billed for
the full scan. With 100 concurrent SSE sessions, this is the dominant
component of the 7M rows read/day we see on prod.
Changes:
- listMessages / getTaskActions: add limit param, default to the new
MAX_TASK_PARTITION_ROWS constant (500). Without since returns the
latest N in ASC order (DESC fetch + reverse). With since returns up
to N after the cursor in ASC order.
- sse.ts: initial fetch asks for 50 rows (no cursor) or 500 (with
cursor). Catch-up polls request 500. When either feed returns
exactly the cap an event gap SSE frame is emitted so the client
can fall back to HTTP instead of silently missing older rows.
- taskRepo.getTaskById now delegates to getTaskActions instead of
duplicating the SQL.
- Known limitation documented for created_at cursor collision.1 parent a9b79ff commit 700594d
6 files changed
Lines changed: 423 additions & 37 deletions
File tree
- apps/web/server
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
21 | 34 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
60 | 70 | | |
61 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
62 | 86 | | |
63 | | - | |
| 87 | + | |
64 | 88 | | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
68 | 92 | | |
69 | | - | |
| 93 | + | |
70 | 94 | | |
71 | 95 | | |
72 | 96 | | |
| |||
85 | 109 | | |
86 | 110 | | |
87 | 111 | | |
88 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
89 | 123 | | |
90 | 124 | | |
91 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 239 | + | |
249 | 240 | | |
250 | | - | |
| 241 | + | |
251 | 242 | | |
252 | 243 | | |
253 | | - | |
| 244 | + | |
254 | 245 | | |
255 | 246 | | |
256 | 247 | | |
| |||
551 | 542 | | |
552 | 543 | | |
553 | 544 | | |
554 | | - | |
555 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
556 | 556 | | |
557 | | - | |
558 | 557 | | |
559 | 558 | | |
560 | | - | |
561 | | - | |
| 559 | + | |
| 560 | + | |
562 | 561 | | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
| 562 | + | |
| 563 | + | |
571 | 564 | | |
572 | 565 | | |
573 | 566 | | |
| |||
0 commit comments