To retrieve the count efficiently from a large table with more than 10 million records, you can use the count method instead of getAll. Here's an example of how you can modify the code:

const transaction = dbo.transaction(['orders'], 'readonly');
const objectStore = transaction.objectStore('orders');
const index = objectStore.index('serviceid, status');

const request = index.count([window['serviceid'], 0]);

request.onsuccess = function(event) {
  const count = event.target.result;
  console.log(count);
};

request.onerror = function(event) {
  console.error("Error occurred while counting records:", event.target.error);
};

This code uses the count method of the index object to directly retrieve the count of records that match the given service ID and status. The result is stored in the count variable, which is then logged to the console

dbotransactionorders readonlyobjectStoreordersindexserviceid statusgetAllwindowserviceid 0; i only need the count consolelog it the table has more than 10 million record plz use fast way

原文地址: https://www.cveoy.top/t/topic/hzCF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录