fix(Pagination): Improve performance of pagination

- Add limit parameter to find method.
 - Set absolute pagination elements limit to 1000.
 - Adding pagination validation, do not accept negative values. If
   negative values are detected, default parameters are used.
This commit is contained in:
2023-10-05 23:23:28 -06:00
parent 8bab3daf57
commit 857a8bf18b

View File

@@ -11,6 +11,10 @@ function getPagination( query ){
}
if( query.elements ){
limit.elements = parseInt( query.elements ) || 10;
/** Safe pagination limit */
if( limit.elements > 1000 ){
limit.elements = 1000;
}
}
return limit;
}
@@ -18,7 +22,7 @@ function getPagination( query ){
async function queryPage( page , elements , model ){
const skip = elements * page;
const total = await model.count();
const list = await model.find( {} , null, { skip : skip } );
const list = await model.find( null , null, { skip : skip , limit : elements } );
return {
total : total,
limit : elements,