Fix: Pagination to consider limit value while returning response. #280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pagination fix
Problem?
Often times in production we don't want to return all matching records instead returning a paginated response based on values of
limit
andoffset
is desirable.What is being fixed?
Even after setting a
limit
value it was not working and.all()
or.execute()
function were returning complete set of records matching the search criterion.How is it fixed?
To break away from loop executing the query a condition is added wherein if total number of fetched records is equal or greater than
limit
.NOTE: If no
limit
is provided, default value i.e. 10 records will be returned. Returning all records is usually a bad idea. Take Elasticsearch or Apache solr for example where if you don't provide a limit, by default only 10 records are returned.