Repository navigation
Commit 6d53c57
fix(opencode): honor --since/--until in the SQLite loader and JSON scan (#1492)
The OpenCode loader read every SQLite row and re-parsed every legacy JSON
message on each invocation, applying --since/--until only after everything had
been loaded. Narrow the work in the loader instead:
- Resolve the bounds to half-open millisecond instants in the reporting
timezone, so the window means the same instants the report means and there is
no slack to justify.
- Push the bounds into SQL through a subquery selecting `id` alone, which the
(session_id, time_created, id) index answers as a covering scan, so
out-of-range rows never have their `data` blob read.
- Skip the full parse for rows and files outside the window using a bounded
scan of the payload's own `time.created`.
- Collapse the three copies of the window predicate into one
`date_within_range`.
Every pre-filter fails open: partial or non-ASCII bounds, a legacy schema with
no `time_created`, a column that is not millisecond scale, a missing payload
timestamp, and column/payload drift up to a day all defer to the authoritative
per-entry check. Source detection asks the filesystem, so the aggregate report
still lists OpenCode when the window excludes everything.
A 7-day window against a synthetic 200k-row / 0.83 GB database goes from
1.133 s to 34.0 ms. Output is byte-identical to main across 67 real-data
comparisons spanning five timezones and twelve window shapes.
Supersedes #1188. Reported in #801 and requested in #867.
Co-authored-by: Justyna Wojtczak <[email protected]>1 parent d7d2dd7 commit 6d53c57
6 files changed
Lines changed: 981 additions & 17 deletions
File tree
- rust
- adapters
- common/src
- opencode/src
- crates
- ccusage-adapter-all/src
- ccusage-core/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
18 | 28 | | |
19 | 29 | | |
20 | 30 | | |
| |||
0 commit comments