-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API section #139
API section #139
Conversation
API - Intro chapter
API - JSON:API chapter
API - Authentication chapter
API - Documentation chapter
API - Versioning chapter
API - Pagination chapter
API - CORS chapter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. Nice work.
|
||
Since this type of pagination allows clients to request any page, it is usually represented in the UI with a paginator where you can select a page (e.g. `<- 2 3 4 5 6 ->`). If this is the kind of UI you're implementing the pagination for, then the page-based type is the right choice. | ||
|
||
This type is also popular because it's easy to implement using SQL's `OFFSET` clause, so you may often hear it being referred to as offset-based pagination. `page[size]=50&page[number]=3` simply translates to `LIMIT 50 OFFSET 50 * (3 - 1) => LIMIT 50 OFFSET 100` in SQL. However, offset-based pagination has a negative side. The clause requires scanning _all_ rows included by the offset value, which is inefficient for large offsets and causes performance to suffer the more pages you have (e.g. page 100 is slower to fetch than page 1). If you don't have to paginate many records, then it's not that much of an issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clause requires scanning all rows included by the offset value, which is inefficient for large offsets and causes performance to suffer the more pages you have
- I am not sure that this is completely true, at least in the PostgreSQL
- As far as I know, there are ways how we can arrange indexes in PostgreSQL so that they can be used for OFFSET
- Another problem is LIMIT, you need to use SORT BY for it, and also as far as I know we can use indexes so that it does not have to sort the whole table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open this as a task so we can discuss it 🙂
Task: #356
Aim
Branch that contains all changes for the API section.
Related private repo PR: https://github.com/infinum/rails-handbook-private/pull/23