Task/address aggregates mv#256
Merged
greatest0fallt1me merged 3 commits intoJun 29, 2026
Merged
Conversation
- Fix broken src/routes/users.ts (missing closing brace, incomplete route) - Remove unused imports in src/services/userService.ts and src/middleware/auth.ts - Add 'silent' to LOG_LEVEL enum in env-schema - Export Db type from src/db/index.ts - Re-export AppError/ErrorCodes from src/errors.ts (resolve module conflict) - Add eslint-disable for namespace declarations in middleware - Add eslint-disable for pre-existing any types in market routes/service - Fix duplicate UserProfile interface in userService.ts - Remove claims table references (table doesn't exist in schema)
- Add address_aggregates_mv MV with rank, accuracy, and prediction counts - Add hourly refresh worker (src/workers/refreshAggregates.ts) - Add addressAggregatesService for CRUD on the MV - Refactor leaderboardService to delegate to addressAggregatesService - Add migration 0013_address_aggregates_mv.sql - Add tests for service, worker, and leaderboard endpoint
|
@CHKM001 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description - Add predictions per address aggregated view (PR #145)
Description
This pull request adds an
address_aggregates_mvmaterialized view that precomputes per-address prediction statistics for fast leaderboard queries. The view is refreshed hourly usingCONCURRENTLYto avoid blocking reads, and is served via the/api/leaderboardendpoint.Requirements Covered
total_predictions,correct_predictions,accuracy_percentage, andrankper usersrc/workers/refreshAggregates.tsruns on a 1-hour interval with.unref()for clean shutdownaddress_aggregates_mvwith pagination and optional?refresh=trueREFRESH MATERIALIZED VIEW CONCURRENTLY; unique index onuser_idis a prerequisitelimit,offset,refresh)Key Changes
New files
drizzle/migrations/0013_address_aggregates_mv.sql: MV DDL withCONCURRENTLY-compatible unique index and supporting indexessrc/services/addressAggregatesService.ts: Shared service withrefreshAddressAggregates(),getAddressAggregates(),getAddressAggregate(),getAddressAggregatesWithRefresh()src/workers/refreshAggregates.ts: Hourly interval worker that callsrefreshAddressAggregates()tests/addressAggregatesService.test.ts: Unit tests for all service functions (6 tests)tests/refreshAggregates.test.ts: Worker lifecycle tests (interval ticking, error recovery, cleanup) (3 tests)tests/leaderboard.test.ts: Route integration tests forGET /api/leaderboardandGET /api/leaderboard/user/:stellarAddress(6 tests)Modified files
src/services/leaderboardService.ts: Refactored to delegate toaddressAggregatesServiceinstead of querying the database directlysrc/index.ts: Imports and starts the refresh worker; cleans up on SIGTERM/SIGINTVerification
All 15 tests pass across 3 test suites:
Closes #145