compact method
Compact the access log. Drops the oldest compactionPercentage of entries by insertion order.
Implementation
@override
Stream<int> compact(bool dryRun) async* {
final int totalKeys = entriesCount();
final int firstN = (totalKeys * (compactionPercentage / 100)).toInt();
final List<int> keysToDelete = _accessLogKeyStore.getFirstNEntries(firstN);
if (dryRun) {
for (final id in keysToDelete) {
yield id;
}
return;
}
try {
await _accessLogKeyStore.removeAll(keysToDelete);
} on Exception catch (e) {
throw DataStoreException(
'DataStoreException while deleting for compaction:${e.toString()}');
} on HiveError catch (e) {
throw DataStoreException(
'Hive error while deleting for compaction:${e.toString()}');
}
for (final id in keysToDelete) {
yield id;
}
}