Skip to content

feat(ab-testing): Add pagination to getAllExperiments() endpoint (#1390) - #1405

Open
chrissarah054-dotcom wants to merge 1 commit into
rinafcode:mainfrom
chrissarah054-dotcom:feat/1390-pagination-experiments
Open

feat(ab-testing): Add pagination to getAllExperiments() endpoint (#1390)#1405
chrissarah054-dotcom wants to merge 1 commit into
rinafcode:mainfrom
chrissarah054-dotcom:feat/1390-pagination-experiments

Conversation

@chrissarah054-dotcom

Copy link
Copy Markdown

closes #1390
BREAKING CHANGE: Response format changed from array to paginated object

  • Replace unbounded find() with paginated createQueryBuilder() + getManyAndCount()
  • Remove eager loading of variants/metrics from list view (performance optimization)
  • Add PaginationQueryDto support for page, limit, sortBy, order parameters
  • Implement SQL injection prevention via sortBy field whitelist validation
  • Return OffsetPaginatedResponse with metadata (total, page, hasNextPage, etc.)
  • Configure default page size: 10 items, max: 100 items per PAGE_SIZE constants

Performance improvements:

  • Query time: O(n) -> O(1) constant regardless of total experiments
  • Memory: O(n×m) unbounded -> O(limit) bounded by page size
  • Response size: Unbounded -> Capped at 100 items maximum
  • Database: Eliminated N+1 query problem via single getManyAndCount()

Database optimization:

  • List view (getAllExperiments): No relation eager loading for bounded queries
  • Detail view (getExperimentById): Maintains full relations (variants, metrics)
  • Indexed createdAt field provides fast sorting and offset pagination

API Changes:
Before: GET /ab-testing/experiments -> Experiment[]
After: GET /ab-testing/experiments -> OffsetPaginatedResponse

Supported query parameters:

  • page (1-based, default: 1)
  • limit (1-100, default: 10)
  • sortBy (createdAt, updatedAt, name, status, startDate; default: createdAt)
  • order (ASC, DESC; default: DESC)

Tests:

  • Added 8 comprehensive pagination test cases
  • Coverage: default pagination, skip/take math, sorting, SQL injection prevention, metadata calculation, no eager loading verification, page size clamping, edge cases

Docs:

  • Full Swagger/OpenAPI documentation with examples
  • Implementation summary with migration guide
  • Performance comparison (before/after metrics)

…afcode#1390)

BREAKING CHANGE: Response format changed from array to paginated object

- Replace unbounded find() with paginated createQueryBuilder() + getManyAndCount()
- Remove eager loading of variants/metrics from list view (performance optimization)
- Add PaginationQueryDto support for page, limit, sortBy, order parameters
- Implement SQL injection prevention via sortBy field whitelist validation
- Return OffsetPaginatedResponse with metadata (total, page, hasNextPage, etc.)
- Configure default page size: 10 items, max: 100 items per PAGE_SIZE constants

Performance improvements:
- Query time: O(n) -> O(1) constant regardless of total experiments
- Memory: O(n×m) unbounded -> O(limit) bounded by page size
- Response size: Unbounded -> Capped at 100 items maximum
- Database: Eliminated N+1 query problem via single getManyAndCount()

Database optimization:
- List view (getAllExperiments): No relation eager loading for bounded queries
- Detail view (getExperimentById): Maintains full relations (variants, metrics)
- Indexed createdAt field provides fast sorting and offset pagination

API Changes:
Before: GET /ab-testing/experiments -> Experiment[]
After:  GET /ab-testing/experiments -> OffsetPaginatedResponse<Experiment>

Supported query parameters:
- page (1-based, default: 1)
- limit (1-100, default: 10)
- sortBy (createdAt, updatedAt, name, status, startDate; default: createdAt)
- order (ASC, DESC; default: DESC)

Tests:
- Added 8 comprehensive pagination test cases
- Coverage: default pagination, skip/take math, sorting, SQL injection prevention,
  metadata calculation, no eager loading verification, page size clamping, edge cases

Docs:
- Full Swagger/OpenAPI documentation with examples
- Implementation summary with migration guide
- Performance comparison (before/after metrics)
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@chrissarah054-dotcom 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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass

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.

getAllExperiments() loads every experiment (with relations) with no pagination

2 participants