Skip to content

Instantly share code, notes, and snippets.

@kierenj
Created December 19, 2017 14:57
Show Gist options
  • Save kierenj/26d9862b2a7415c0c973c98031e2d0d5 to your computer and use it in GitHub Desktop.
Save kierenj/26d9862b2a7415c0c973c98031e2d0d5 to your computer and use it in GitHub Desktop.
Paging defaults

Paging by default

problems

  • easy to forget default limit is there - get dropdowns with just a few options, etc
  • have to specify arbitrary-ish big number for page_size to remove limit. how to choose?

benefits

  • not having to remember to implement paging
  • query performance by default

possible solutions

  1. don't used PagedView<> for lookups or queries where consumer probably won't want paging
  2. don't make page_number optional for queries with paging: throw error if missing. can't mistake that it's a paged view then
  3. only use paging if page_number/page_size specified

KJ - prefer 1&2, 3 could mean getting in the habit of not paging, having slow queries + big results pages?

@kierenj
Copy link
Author

kierenj commented Jan 17, 2018

Would there be much of a downside to mandating a pageNumber query parameter for paged queries? So the caller definitely knows it's paged then? I know from the sounds of it other APIs just default it, and the biggest positive change is carefully considering which endpoints should be paged, but this seems almost free/easy-ish?

@sam-rr
Copy link

sam-rr commented Jan 18, 2018

Yes I think that is reasonable, that in combination with the pageSize max limit should enforce good responsible usage of paged endpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment