Why doesn't TypeORM skip() and take() function work?

60 views Asked by At

The Delivery table has got more than 4 million rows. I used MySQL database.

async adminDeliveriesViewCount (data) {
 try {
   const batchSize = 10;
   let batchIndex = 0, totalDeliveries = 0;
   while(true) {
     let total = await Delivery.createQueryBuilder().skip(batchIndex * batchSize).take(batchSize)
       .getCount();

     if(total == 0) break;
     totalDeliveries += total;
     ++ batchIndex;
   }

   return totalDeliveries;
 } catch (e) {
   new ErrorHandler(e, 'adminDeliveriesViewCount');
 }
}

This function is not working. The "total" value is always the total number of rows in the table.

I tried changing the "batchSize" and "batchIndex", but it didn't help. Can anyone help me?

0

There are 0 answers