Skip to content

Commit f0006b3

Browse files
author
abluchet
committed
doc partial pagination
1 parent 2177b97 commit f0006b3

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

core/configuration.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ api_platform:
7979

8080
swagger:
8181
# The swagger api keys.
82-
api_keys: []
82+
api_keys: []
8383

8484
collection:
8585
# The default order of results.
@@ -113,6 +113,16 @@ api_platform:
113113
# The name of the query parameter to set the number of items per page.
114114
items_per_page_parameter_name: 'itemsPerPage'
115115

116+
# To allow partial pagination for all resource collections.
117+
# This improves performances by skipping the `COUNT` query.
118+
partial: true
119+
120+
# To allow the client to enable or disable the partial pagination.
121+
client_partial: true
122+
123+
# The name of the query parameter to enable or disable the partial pagination.
124+
partial_parameter_name: 'partial' # Default value
125+
116126
mapping:
117127
# The list of paths with files or directories where the bundle will look for additional resource files.
118128
paths: []

core/pagination.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,76 @@ class Book
205205
}
206206
```
207207

208+
## Partial Pagination
209+
210+
When using the default pagination, a `COUNT` query will be issued against the current requested collection. This may have a
211+
performance impact on really big collections. The downside is that the information about the last page is lost (ie: `hydra:last`).
212+
213+
### Globally
214+
215+
The partial pagination retrieval can be configured for all resources:
216+
217+
```yaml
218+
# app/config/config.yml
219+
220+
api_platform:
221+
collection:
222+
pagination:
223+
partial: true # Disabled by default
224+
```
225+
226+
### For a Specific Resource
227+
228+
```php
229+
<?php
230+
231+
// src/AppBundle/Entity/Book.php
232+
233+
use ApiPlatform\Core\Annotation\ApiResource;
234+
235+
/**
236+
* @ApiResource(attributes={"pagination_partial"=true})
237+
*/
238+
class Book
239+
{
240+
// ...
241+
}
242+
```
243+
244+
### Client-side
245+
246+
#### Globally
247+
248+
```yaml
249+
# app/config/config.yml
250+
251+
api_platform:
252+
collection:
253+
pagination:
254+
client_partial: true # Disabled by default
255+
partial_parameter_name: 'partial' # Default value
256+
```
257+
258+
The partial pagination retrieval can now be changed by toggling a query parameter named `partial`: `GET /books?partial=true`
259+
260+
#### For a Specific Resource
261+
262+
```php
263+
<?php
264+
265+
// src/AppBundle/Entity/Book.php
266+
267+
use ApiPlatform\Core\Annotation\ApiResource;
268+
269+
/**
270+
* @ApiResource(attributes={"pagination_client_partial"=true})
271+
*/
272+
class Book
273+
{
274+
// ...
275+
}
276+
```
277+
208278
Previous chapter: [Validation](validation.md)
209279

210280
Next chapter: [The Event System](events.md)

core/performance.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ api_platform:
219219

220220
The whole configuration seen before will no longer work and Doctrine will recover its default behavior.
221221

222+
### Partial Pagination
223+
224+
When using the default pagination, the Doctrine paginator will execute a `COUNT` query on the collection. The result of the
225+
`COUNT` query is used to compute the latest page available. With big collections this can lead to quite long response times.
226+
If you don't mind not having the latest page available, you can enable partial pagination and avoid the `COUNT` query:
227+
228+
```
229+
# app/config/config.yaml
230+
231+
api_platform:
232+
collection:
233+
pagination:
234+
partial: true # Disabled by default
235+
```
236+
237+
More details are available on the [pagination documentation](pagination.md#partial-pagination).
238+
222239
Previous chapter: [Security](security.md)
223240

224241
Next chapter: [Operation Path Naming](operation-path-naming.md)

index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
9. [Pagination](core/pagination.md)
5454
1. [Disabling the Pagination](core/pagination.md#disabling-the-pagination)
5555
2. [Changing the Number of Items per Page](core/pagination.md#changing-the-number-of-items-per-page)
56+
3. [Partial Pagination](core/pagination.md#partial-pagination)
5657
10. [The Event System](core/events.md)
5758
11. [Content Negotiation](core/content-negotiation.md)
5859
1. [Enabling Several Formats](core/content-negotiation.md#enabling-several-formats)
@@ -79,6 +80,7 @@
7980
2. [Force Eager](core/performance.md#force-eager)
8081
3. [Override at Resource and Operation Level](core/performance.md#override-at-resource-and-operation-level)
8182
4. [Disable Eager Loading](core/performance.md#disable-eager-loading)
83+
3. [Partial Pagination](core/performance.md#partial-pagination)
8284
18. [Operation Path Naming](core/operation-path-naming.md)
8385
1. [Configuration](core/operation-path-naming.md#configuration)
8486
2. [Create a Custom Operation Path Naming](core/operation-path-naming.md#create-a-custom-operation-path-resolver)

0 commit comments

Comments
 (0)