Skip to content

feat(marketplace): add indexer-backed caching and pagination (#504) - #552

Merged
barry01-hash merged 1 commit into
PromptMintLabs:mainfrom
NnamdiCyber:feat/504-marketplace-cache-pagination
Aug 31, 2026
Merged

feat(marketplace): add indexer-backed caching and pagination (#504)#552
barry01-hash merged 1 commit into
PromptMintLabs:mainfrom
NnamdiCyber:feat/504-marketplace-cache-pagination

Conversation

@NnamdiCyber

Copy link
Copy Markdown
Contributor

Summary

Closes #504 — adds caching and pagination for the high-volume marketplace, served from the event indexer's Prompt collection (roadmap item: external indexer for search/pagination at scale).

The previous GET /api/prompts returned every published prompt with no pagination, search, or sort — untenable at scale. It now reads from the indexed collection through a cached, paginated, searchable read model.

Changes

  • models/Prompt.js: added a full-text search index (title/content/category/tags) and compound sort indexes (createdAt, price, salesCount, rating, each paired with _id) so search/pagination avoid full collection scans.
  • services/marketplaceIndexService.ts (new): the indexer-backed read model. searchMarketplace() supports:
    • Filtering: search, category, tags, minPrice/maxPrice, similarityFlag, walletAddress
    • Sorting: newest, oldest, price_asc/price_desc, sales, rating, relevance
    • Pagination: offset (page/limit, clamped to 100) and opaque keyset cursor pagination for deep, high-volume scans (no expensive skip)
    • Cache-aside in Redis keyed by normalized query (incl. cursor) under prompts:list:* — automatically invalidated by invalidatePromptMetadata on every indexed contract event
  • controllers/controllers.ts: GetPrompts delegates to searchMarketplace, returning a paginated envelope (items / total / page / limit / totalPages / nextCursor / hasNext / cached) instead of a bare array. Added GetMarketplaceIndexStatus.
  • routes/promptRoutes.ts: new GET /api/prompts/index/status for indexer visibility (registered before /:id).
  • Tests: marketplaceIndexService.test.ts + getPrompts.test.ts — 10/10 passing.

Test plan

cd server && npx jest src/tests/marketplaceIndexService.test.ts src/tests/getPrompts.test.ts

Usage

GET /api/prompts?search=...&category=Programming&tags=ai,seo&minPrice=1&maxPrice=50&sort=price_desc&limit=24&cursor=

Notes

  • The server/package-lock.json change from local npm install was intentionally excluded from the commit.
  • tsc reports pre-existing type errors across many controllers (the asyncRoute/AsyncHandler mismatch from @types/express@5); none are introduced by this change, and the new code is type-clean.

…intLabs#504)

Replace the all-rows GetPrompts listing with a cached, paginated,
searchable read model served from the event-indexed Prompt collection.

- Add text + compound sort indexes to Prompt for scale
- Add marketplaceIndexService: search/filter/sort with offset and
  keyset-cursor pagination, cache-aside in Redis under prompts:list:*
- GetPrompts returns a paginated envelope (items/total/page/nextCursor/...)
- Add GET /api/prompts/index/status for indexer visibility
- Cover service and controller with tests
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@NnamdiCyber 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! 🚀

Learn more about application limits

@barry01-hash
barry01-hash merged commit 259c37d into PromptMintLabs:main Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add caching and pagination for high-volume marketplace

2 participants