typeorm-pagination icon indicating copy to clipboard operation
typeorm-pagination copied to clipboard

[BUG]: when calling 2 endpoints together (with Promise.all) the page & per_page are set incorrectly

Open jclaessens97 opened this issue 3 years ago • 1 comments

I noticed when calling 2 endpoints with Promise.all, the pagination parameters for page & per_page are not working correctly. It always takes the parameters of the last endpoint in the list.

image

image

When I call them one by one or with only one in the Promise.all, it does work correctly

jclaessens97 avatar Nov 26 '21 10:11 jclaessens97

Been having the same problem with concurrent requests on my Nest JS backend.

Solved it by making the following changes to the code: Changed the paginate method to accept an object with {per_page, page} Change the priority of the parameters to: 1st the object passed to paginate 2nd the query object on the request 3rd the default values.

What was happening in my case is that the 1st request was setting per_page to X, and before the query was executed, the second request came and changed per_page to Y. Using the parameters passed directly to .paginate solved it for me.

williamlac avatar May 25 '22 17:05 williamlac