vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

Add page size limit #715

Closed pulpn0ir closed 3 years ago

pulpn0ir commented 3 years ago

Adds a means to prevent server overloads by limiting the maximum amount of elements returned in a single page.

Application and Request have been extended with setters for page size limits. Set limits using the newly introduced PageLimit type.

// Set page size limit for the current request. Default is `nil`, which means no limit. 
request.fluent.pagination.pageSizeLimit = 3

// Setting the request-level limit to `nil` will cause the application-level limit to be used instead. 
request.fluent.pagination.pageSizeLimit = nil

// Use `.noLimit` if you intend to override a limit set on application level. 
request.fluent.pagination.pageSizeLimit = .noLimit

// Set application-wide page size limit. Default is `nil`, which means no limit. 
application.fluent.pagination.pageSizeLimit = 3

This PR depends on: https://github.com/vapor/fluent-kit/pull/412

siemensikkema commented 3 years ago

The tests are failing due to unrelated changes.

Besides reporting these I think we should update CI to not depend on nightly builds. @gwynne @0xTim agreed?

0xTim commented 3 years ago

@siemensikkema agree, for most things we should probably be testing with lowest supported version (5.2 release) and current release (5.4). It might be beneficial to test against latest master to catch Swift regressions but there's no point testing against a nightly build of a released Swift version

VaporBot commented 3 years ago

These changes are now available in 4.3.0