Skip to content

Inefficient Pagination using .skip() for Large Datasets #165

Description

@DioChuks

Description

In EventTicketService.getEventTickets and TicketOrderService, pagination is implemented using MongoDB's .skip(offset) method. While acceptable for small datasets, .skip() requires the database to scan and discard all documents up to the offset, resulting in O(N) performance degradation as the page number increases.

Proposed Solution

Implement cursor-based (keyset) pagination for endpoints that are expected to handle large datasets (e.g., ticket orders, event listings). Instead of passing page, clients should pass a cursor (usually the _id and sort field of the last item).

Acceptance Criteria

  • EventTicketService.getEventTickets updated to support cursor-based pagination.
  • TicketOrderService updated to support cursor-based pagination.
  • API documentation updated to reflect the new pagination parameters.
  • Tests added to verify cursor logic.

Files

  • src/services/event-ticket.service.ts
  • src/services/ticket-order.service.ts

Notes

For backward compatibility, the page query parameter can be maintained with .skip() as a fallback, but cursor should be preferred.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions