Description
Markets pages need at-a-glance pool totals per outcome. Add an aggregate endpoint backed by a small materialized view refreshed by the predictions confirmer worker, so reads are O(rows-in-result) and never scan predictions.
Requirements and Context
- MV
market_outcome_totals with (market_id, outcome, total_amount, prediction_count)
- Refreshed at the end of every confirmer tick
GET /api/markets/:id/predictions/aggregate returns the rows
- Caches
Cache-Control: max-age=5 for browser clients
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feature/market-aggregate-endpoint
- Implement changes
- SQL migration creating MV
- Hook refresh into
src/workers/predictionsConfirmer.ts
src/routes/markets.ts aggregate handler
- Test and commit
- Seed predictions, run confirmer, assert totals
- Cover edge cases
- Include test output and notes in the PR
Example commit message
feat: market outcome aggregates endpoint
Acceptance Criteria
Guidelines
- Use
numeric(78,0) for total_amount
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
Markets pages need at-a-glance pool totals per outcome. Add an aggregate endpoint backed by a small materialized view refreshed by the predictions confirmer worker, so reads are O(rows-in-result) and never scan
predictions.Requirements and Context
market_outcome_totalswith(market_id, outcome, total_amount, prediction_count)GET /api/markets/:id/predictions/aggregatereturns the rowsCache-Control: max-age=5for browser clientsSuggested Execution
src/workers/predictionsConfirmer.tssrc/routes/markets.tsaggregate handlerExample commit message
Acceptance Criteria
supertestrepeat callGuidelines
numeric(78,0)fortotal_amount