Backend: indexes, cursor pagination, Stellar address validation, and market cache - #1320
Merged
Merged
Conversation
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.
Summary
Backend: indexes, cursor pagination, Stellar address validation, and market cache
What was solved
#1243 — B-65: Add Bet index on bettor for address queries
Add database indexes to support address-based Bet queries and Market list queries: a composite index on Bet leading with bettor (plus placedAt) and a composite index on Market (status, scheduledAt), delivered via a new Prisma migration and schema.prisma update.
Addressed:
#1244 — B-66: Cursor pagination for market bets and user bets
Add cursor-based pagination (max limit 100) to the market bets and user bets endpoints, with stable ordering by (placedAt, id) and a nextCursor in the response, plus tests covering first, middle, and last pages.
Addressed:
#1245 — B-67: Shared zod schema for Stellar address params
Add a shared
stellarAddresszod schema built onStrKey.isValidEd25519PublicKeyin the backend validation middleware, and apply it to all routes with:addressparams so invalid addresses return HTTP 400 with error codeINVALID_ADDRESS.Addressed:
stellarAddresszod schema inbackend/src/api/middleware/validate.tsthat validates Stellar Ed25519 public keys usingStrKey.isValidEd25519PublicKeyfrom@stellar/stellar-sdk(or the SDK already used in the repo).stellarAddressschema to every route param named:address(e.g. bet routes, user routes, and any other route declaring:address).INVALID_ADDRESS.#1246 — B-68: Cache market list and stats in Redis
Add short-TTL Redis caching for market list and stats responses in the market service, and invalidate the relevant cache keys from the indexer when BetPlaced or market status events are processed. Include cache hit/miss ratio logging to satisfy the acceptance criteria.
Addressed:
Changes
backend/prisma/schema.prisma(modify)backend/prisma/migrations/20260626000000_add_market_search/migration.sql(modify)backend/src/services/bet.service.ts(modify)backend/src/api/controllers/market.controller.ts(modify)backend/src/api/controllers/user.controller.ts(modify)backend/src/api/middleware/validate.ts(modify)backend/src/api/routes/bet.routes.ts(modify)backend/src/services/market.service.ts(modify)backend/src/services/indexer.service.ts(modify)backend/src/config.ts(modify)Approach
Issues
Closes #1243
Closes #1244
Closes #1245
Closes #1246