message: Fix progress calculation on compact
diff: @@ -198,9 +198,15 @@ export default class Combined implements DiskStore {
  return headerAt;
  }
  - private _compact (progress: (value: ProgressValue) => void, newFd: number, oldFd: number, newAt: number = 0, oldAt: number = 0, depth: number = 0, keys: number = 0, percent: number = 0): number {
  + private _compact (progress: (value: ProgressValue) => void, newFd: number, oldFd: number): number {
  // l.debug(() => ['_compact', debug({ newFd, oldFd, newAt, oldAt })]);
  + let keys = 0;
  + let percent = 0;
  +
  + const doCompact = (newAt: number, oldAt: number, depth: number) => {
  + const increment = (100 / ENTRY_NUM) / Math.pow(ENTRY_NUM, depth);
  +
  for (let index = 0; index < ENTRY_NUM; index++) {
  const entry = this._compactReadEntry(oldFd, oldAt, index);
  const dataAt = entry.readUIntBE(1, UINT_SIZE);
  @@ -208,6 +214,7 @@ export default class Combined implements DiskStore {
  if (entryType === Slot.EMPTY) {
  // l.debug(() => '_compact/isEmpty');
  + percent += increment;
  } else if (entryType === Slot.LEAF) {
  // l.debug(() => '_compact/isLeaf');
  @@ -217,18 +224,17 @@ export default class Combined implements DiskStore {
  this._compactUpdateLink(newFd, newAt, index, keyAt, Slot.LEAF);
  keys++;
  + percent += increment;
  } else if (entryType === Slot.BRANCH) {
  // l.debug(() => '_compact/isBranch');
  const headerAt = this._compactWriteHeader(newFd, newAt, index);
  - keys = this._compact(progress, newFd, oldFd, headerAt, dataAt, depth + 1, keys, percent);
  + doCompact(headerAt, dataAt, depth + 1);
  } else {
  throw new Error(`Unknown entry type, ${entryType}`);
  }
  - percent += (100 / ENTRY_NUM) / Math.pow(ENTRY_NUM, depth);
  -
  progress({
  depth,
  keys,
  @@ -237,6 +243,9 @@ export default class Combined implements DiskStore {
  }
  // l.debug(() => ['_compact', '=>', `${depth}: ${keys} keys written`]);
  + };
  +
  + doCompact(0, 0, 0);
  return keys;
  }
  