gregbrowndev / projects

1 stars 0 forks source link

Add paginated result DTO #59

Open gregbrowndev opened 1 year ago

gregbrowndev commented 1 year ago

For paginated queries, we should return a result type that contains the page info. E.g.

case class PageInfoDTO(offset: Int, limit: Int, records: Int)

case class JobDTO(...)

case class JobsQueryResultDTO(pageInfo: PageInfoDTO, jobs: List[JobDTO])

Note: The offset-based pagination approach used above has some disadvantages. If the data changes (records added/modified/removed) such that the ordering changes, the user may see duplicated results as they paginate through the data.

Additionally, the query contains the total number of records, which entails doing a COUNT(*), to derive the total number of pages. In large datasets, this may be expensive.

We could also include an infinite-scroller style of pagination to avoid page numbering:

case class VirtualPageInfoDTO(offset: Int, limit: Int, hasPreviousPage: Boolean, hasNextPage: Boolean)

And use cursor-based pagination to prevent the other issues.