Efficiently Count Records in IndexedDB with 10 Million+ Records
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.
原文地址: https://www.cveoy.top/t/topic/o2pJ 著作权归作者所有。请勿转载和采集!