Commit 447c404
committed
fix(billing): deterministic apportionment order, block audit export during stale data
Cursor Bugbot caught two more real issues on the latest push:
1. Same stale-export bug as the earlier Credit usage fix, this time in
Audit Logs: Export stayed enabled while useAuditLogs held prior
rows via keepPreviousData, so it could export against a
just-changed filter while the table still showed the old one. Now
also disabled while isPlaceholderData is true.
2. getUsageCreditsByLogId had no ORDER BY before apportionCredits's
largest-remainder tie-break, so which row absorbed a tied
remainder credit depended on undefined Postgres row order — the
same event's displayed credit could flip between calls (list vs.
export, or even two successive requests). Added the same
`orderBy(desc(createdAt), desc(id))` the main list query already
uses, making the tie-break reproducible.
Verified live: 3 identically-costed rows produced the same tie-break
winner across 3 repeated requests (previously order-dependent).1 parent bd67ebd commit 447c404
2 files changed
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
301 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
302 | 309 | | |
303 | 310 | | |
304 | 311 | | |
| |||
403 | 410 | | |
404 | 411 | | |
405 | 412 | | |
406 | | - | |
| 413 | + | |
407 | 414 | | |
408 | 415 | | |
409 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
| |||
0 commit comments