autobee 2.11.1 → 2.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +12 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -684,14 +684,15 @@ module.exports = class Autobee extends ReadyResource {
684
684
  }
685
685
 
686
686
  async compactMaybe() {
687
- if (!this.writers.writable) return
688
-
689
687
  if (await this._isReindexed()) return
690
688
 
691
- await this._reindexBee(this._workingBee)
689
+ const latest = await this.writers.getLatestLocalOplog()
690
+ const views = latest ? latest.views : null
691
+
692
+ await this._reindexBee(this._workingBee, views ? views.view : null)
692
693
  this.bee.move(this._workingBee.head())
693
694
 
694
- await this._reindexBee(this.system.bee)
695
+ await this._reindexBee(this.system.bee, views ? views.system : null)
695
696
 
696
697
  this._reindexed = true
697
698
  }
@@ -706,18 +707,18 @@ module.exports = class Autobee extends ReadyResource {
706
707
  return !(await this._shouldReindex(view.key))
707
708
  }
708
709
 
709
- async _reindexBee(bee) {
710
+ async _reindexBee(bee, flushed) {
710
711
  const head = bee.head()
711
712
  const local = bee.context.local
712
713
  if (head === null) return
713
- if (await this._shouldReindex(local.key)) return
714
714
  if (!(await this._shouldReindex(head.key))) return
715
715
 
716
- // a non-empty local core is a completed reindex whose head was never stored
717
- if (local.length === 0) {
718
- await bee.reindex(async (change) => !(await this._shouldReindex(change.head.key)))
716
+ if (flushed && flushed.key && b4a.equals(flushed.key, local.key)) {
717
+ bee.move({ key: local.key, length: flushed.start + flushed.length })
718
+ return
719
719
  }
720
720
 
721
+ await bee.reindex(async (change) => !(await this._shouldReindex(change.head.key)))
721
722
  bee.move({ key: local.key, length: local.length })
722
723
  }
723
724
 
@@ -793,6 +794,7 @@ module.exports = class Autobee extends ReadyResource {
793
794
 
794
795
  if (this.fastForwardTo !== null) {
795
796
  await this._applyFastForward()
797
+ await this.compactMaybe()
796
798
  if (changes) changes.track()
797
799
  this._needsUpdate = false
798
800
  break // revaluate conditions...
@@ -1452,13 +1454,7 @@ module.exports = class Autobee extends ReadyResource {
1452
1454
 
1453
1455
  const changed = await this.system.flush(batch, this._workingBee)
1454
1456
 
1455
- if (this._reindexed && (await this._isReindexed())) {
1456
- this._reindexed = false
1457
- await this.local.setUserData(
1458
- 'autobee/head',
1459
- encoding.encodeBootRecord(this.system.bootRecord())
1460
- )
1461
- }
1457
+ if (this._reindexed && (await this._isReindexed())) this._reindexed = false
1462
1458
 
1463
1459
  if (this.system.promotions.changed) this._prefetchApprovals().catch(safetyCatch)
1464
1460
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.11.1",
3
+ "version": "2.11.3",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",