#597 Measures: the PostgreSQL change index, balances and split totals (#595)
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#597
- pull request
- state:merged
Part 2 of #595. Stacked on #596: until that merges, this diff includes its commit. A server timeline keeps a **change index**: a persistent AVL tree (`oc_change_nodes`, rooted at `change_root`) of the times its measures' changes apply. Each node keeps its own changes and its subtree's totals. - **Forks and views:** the tree is versioned like the other index tables, so forks share and retire its rows. Separation views build their own (`oc_view_change_nodes`). - **Maintenance:** - Rebuilds and views write it whole (`changePoints`). - Sparse saves subtract each changed moment's and duration's old changes and add their new ones. Durations move with the moments they follow. - Changing where a measure's durations apply (start or end) rebuilds the index. - **Reading:** `oc_change_prefixes` reads the changes up to several times, one path each, in a single call per query. It has view and fork variants like the other walks. - **Overviews** split their totals across summaries and give `balances` and `balanceAfter`, using the same functions as the editor. Every change in the window counts once. - **Migration:** index version 4. Timelines with measures indexed before this are rebuilt once. - **Ongoing durations:** their placeholders no longer adjust totals, since the totals already count their changes. **Tests:** - `test/measure-balance-postgres.mjs`, added to CI, checks split totals and balances against hand sums. It runs through random sparse saves (moments and durations added, moved, revalued and deleted; durations ending where moments are), in a copy reading through to its original and saving on its own, in a tag separation, and after a rebuild forced by changing where a measure's durations apply. - Locally, these also pass: `incremental-postgres`, `fork-read-through-postgres` (482 revisions), `summaries-postgres`, `views-postgres`, `durations-postgres`, `ongoing-durations-postgres`, `tree-paths-postgres`, `openapi-postgres`, `measures-postgres` and `measure-totals-postgres`. The last now checks every duration starting in the window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/circagraph/timeline-app/pull/597
Related
- #595 Measures: running balances from changes, and one change index per timeline
- #596 Measures: balances, durations at start or end, and totals that split the window (#595)
- #598 Measures: the SQLite change index for desktop files (#595)
- #602 Measures: balances in the editor, a balance chart and api.balance (#595)
- Merge pull request #597 from openchronology/feat/595-postgres-balances
Open #597 Measures: the PostgreSQL change index, balances and split totals (#595) in the timeline