compact method
Compact the database
Implementation
@override
Future compact() async {
var txn = _idbDatabase.transaction([
idbInfoStore,
idbEntryStore,
], idbModeReadWrite);
var deltaMinRevision = await _txnGetDeltaMinRevision(txn);
var currentRevision = await _txnGetRevision(txn) ?? 0;
var newDeltaMinRevision = deltaMinRevision;
var deleteIndex = txn.objectStore(idbEntryStore).index(idbDeletedIndex);
await deleteIndex.openCursor(autoAdvance: true).listen((cwv) {
assert(cwv.key is int);
var revision = cwv.primaryKey as int;
if (revision > newDeltaMinRevision && revision <= currentRevision) {
newDeltaMinRevision = revision;
cwv.delete();
}
}).asFuture<void>();
// devPrint('compact $newDeltaMinRevision vs $deltaMinRevision, $currentRevision');
if (newDeltaMinRevision > deltaMinRevision) {
await _txnPutDeltaMinRevision(txn, newDeltaMinRevision);
}
await txn.completed;
}