Repository navigation
feat(api): store per-asset headline figures for the overview - #1375
Conversation
|
@Glorious21 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
royalTreasure
left a comment
There was a problem hiding this comment.
Thanks @Glorious21. Storing per-asset headline figures fits #575. CI is green, but it can't be merged yet: migration v4 is now taken. #1353 (per-asset matching windows) just landed on main as ORG_MIGRATIONS v4, so this branch conflicts and its v4 migration and org-v4.db fixture no longer line up.
To fix:
git fetch upstream && git rebase upstream/main(please rebase, don't mergemainin).- Renumber your migration to the next free version (v5 today). Several open PRs add a migration, so whichever merges first takes v5 and the rest move up again.
- Regenerate the fixture with
services/api/test/fixtures/make-db-fixtures.tsasorg-v5.db(keepmain'sorg-v4.dbunchanged), and update the pinned schema digest and migration tests. - Update the version number in `docs/schema.md` and in your `CHANGELOG.md` line to match. Run
pnpm build && pnpm typecheck && pnpm lint && pnpm testand force-push.
The dashboard polls the overview every few seconds, and each call replayed events, rebuilt the controls log and re-read every action and run per asset. An asset_stats row now holds supply, holder and event counts, incompleteness, the latest run and the open-break counts. overview() and assetSummary() read it; a missing row is recomputed and stored. The row is rewritten at the end of every change that can move a figure: a sync pass (including one that adds nothing, since the controls log runs to the read-through time, and one that fails after committing pages), a rebuild, a reconciliation, a deleted register, a sign-off, an instructions import, a corporate action's reconciliation and an asset settings change (its matching windows decide which controls break). An asset that was never synced is always recomputed. ORG_MIGRATIONS v6 adds the table, with the org-v6 fixture, upgrade tests, the pinned digest, the cascade test row and docs. Closes useconcord#575
4e961b8 to
4910933
Compare
|
Thanks @royalTreasure, done. The branch is rebased onto
One addition from the rebase. #1353 made Results:
#1366 is also on v6 now. Whichever of the two lands second, I'll move it to v7. |
royalTreasure
left a comment
There was a problem hiding this comment.
Thanks @Glorious21, and thanks for rebasing. The change still fits #575 and CI was green, but migration v6 was just taken: #1366 (holdings checkpoints) merged into main as ORG_MIGRATIONS v6, so this branch conflicts again and its v6 migration and org-v6.db fixture no longer line up.
To fix:
git fetch upstream && git rebase upstream/main(please rebase, don't mergemainin).- Renumber your migration to the next free version (v7 today). Other open PRs also add a migration, so whichever merges first takes v7 and the rest move up again.
- Regenerate the fixture with
services/api/test/fixtures/make-db-fixtures.tsasorg-v7.db(keepmain'sorg-v6.dbunchanged), and update the pinned schema digest and migration tests. - Update the version number in
docs/schema.mdand in yourCHANGELOG.mdline to match. Runpnpm build && pnpm typecheck && pnpm lint && pnpm testand force-push.
|
Thanks @Glorious21! Each asset's headline figures are stored in |
closes #575
Summary
The dashboard polls
/overviewevery 4 to 30 seconds. For every asset, each call replayed the events for supply and holders, rebuilt the controls log, and re-read every corporate action and the latest run. The figures now live in oneasset_statsrow per asset, whichoverview()andassetSummary()read, so a poll costs the same however long the history is.Changes
services/api/src/schema.ts:ORG_MIGRATIONSentry 6 (aftermain's v4 matching windows and v5 tolerance) addsasset_stats (asset_id, supply, holder_count, event_count, incomplete, last_run, open_reconciliation, open_controls, open_actions, updated_at), cascading fromassets.services/api/src/concord.tscomputeStats()is the previous computation, unchanged.refreshStats()recomputes the figures and stores the row.assetSummary()reads the row. If it's missing (for example after an upgrade), it computes and stores it. An asset that has never synced is always recomputed: its controls log runs to the clock and it has nothing to replay.rebuild, before its (possibly deferred) re-index.reconcileanddeleteRegister, whose cascade can remove the latest run.setNote, for any scope.importInstructions.reconcileAction, which coverscreateActionandreconcileDue./overviewand/assets/:id. Unwatching an asset deletes its row by cascade.org-v6.dbfixture and itsmake-db-fixtures.tsentry, upgrade tests from v5 and v6, the pinned digest intenancy.test.ts, the cascade test seed row, anddocs/schema.md, which documents the table and what rewrites it.CHANGELOG.mdgets an entry. The older fixtures are byte-for-byte unchanged.Verification
Consistency test ("keeps the overview's stored figures equal to a full recompute after every kind of change"). It walks one asset through:
reconcileDueafter a later sync.After each step, the served overview must equal the overview recomputed from scratch with every
asset_statsrow deleted. I confirmed it fails at the matching step when the hook is removed fromreconcile, from the sync pass, or fromreconcileAction.Latency independent of event count. With 10,007 events indexed, a poll of
overview()runs no SQL againstevents,runs,actions,instructions,break_notesoropenings. It reads onlyassetsandasset_stats.Commands run:
pnpm --filter @concord/api test: 309/311 pass.pnpm --filter @concord/api typecheckandeslint services/api/src: clean.The two failing tests are unrelated to this change. They fail only on my Windows checkout:
README CLI examplesbecause README.md is checked out with CRLF line endings, andresolves relative CONCORD_DATA_DIRbecause it expects POSIX absolute paths.Note for merging
#1366 (holdings checkpoints, #576) is also rebased onto
mainasORG_MIGRATIONSentry 6 with anorg-v6.dbfixture. Whichever of the two merges second needs its migration renumbered to 7, with anorg-v7.dbfixture, the digest appended and the doc wording updated. I'll do that on whichever lands second.