autobee 2.11.2 → 2.11.4
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.
- package/index.js +17 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const migrations = require('./lib/migrations.js')
|
|
|
29
29
|
const EMPTY_HEAD = { length: 0, key: null }
|
|
30
30
|
const DEFAULT_ACK_THRESHOLD = 32
|
|
31
31
|
const BOOT_NETWORK_TIMEOUT = 5000
|
|
32
|
+
const REINDEX_PREFETCH = 4096
|
|
32
33
|
const INTERRUPT = new Error('Apply interrupted')
|
|
33
34
|
|
|
34
35
|
module.exports = class Autobee extends ReadyResource {
|
|
@@ -150,6 +151,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
150
151
|
this._preapply = handlers.preapply || null
|
|
151
152
|
this._preApplied = false
|
|
152
153
|
this._reindexed = false
|
|
154
|
+
this._strictReindex = !!handlers.strictReindex
|
|
153
155
|
this._warmup = handlers.warmup || null
|
|
154
156
|
this._hasApply = !!handlers.apply
|
|
155
157
|
this._hasUpdate = !!handlers.update
|
|
@@ -686,10 +688,13 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
686
688
|
async compactMaybe() {
|
|
687
689
|
if (await this._isReindexed()) return
|
|
688
690
|
|
|
689
|
-
await this.
|
|
691
|
+
const latest = await this.writers.getLatestLocalOplog()
|
|
692
|
+
const views = latest ? latest.views : null
|
|
693
|
+
|
|
694
|
+
await this._reindexBee(this._workingBee, views ? views.view : null)
|
|
690
695
|
this.bee.move(this._workingBee.head())
|
|
691
696
|
|
|
692
|
-
await this._reindexBee(this.system.bee)
|
|
697
|
+
await this._reindexBee(this.system.bee, views ? views.system : null)
|
|
693
698
|
|
|
694
699
|
this._reindexed = true
|
|
695
700
|
}
|
|
@@ -704,17 +709,20 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
704
709
|
return !(await this._shouldReindex(view.key))
|
|
705
710
|
}
|
|
706
711
|
|
|
707
|
-
async _reindexBee(bee) {
|
|
712
|
+
async _reindexBee(bee, flushed) {
|
|
708
713
|
const head = bee.head()
|
|
709
714
|
const local = bee.context.local
|
|
710
715
|
if (head === null) return
|
|
711
716
|
if (!(await this._shouldReindex(head.key))) return
|
|
712
717
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
718
|
+
if (flushed && flushed.key && b4a.equals(flushed.key, local.key)) {
|
|
719
|
+
bee.move({ key: local.key, length: flushed.start + flushed.length })
|
|
720
|
+
return
|
|
716
721
|
}
|
|
717
722
|
|
|
723
|
+
await bee.reindex(async (change) => !(await this._shouldReindex(change.head.key)), {
|
|
724
|
+
prefetch: REINDEX_PREFETCH
|
|
725
|
+
})
|
|
718
726
|
bee.move({ key: local.key, length: local.length })
|
|
719
727
|
}
|
|
720
728
|
|
|
@@ -729,7 +737,8 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
729
737
|
}
|
|
730
738
|
|
|
731
739
|
if (core.manifest === null) return unknown
|
|
732
|
-
|
|
740
|
+
if (core.manifest.version >= DEFAULT_MANIFEST_VERSION) return false
|
|
741
|
+
return this._strictReindex || core.manifest.version > 1
|
|
733
742
|
} finally {
|
|
734
743
|
await core.close()
|
|
735
744
|
}
|
|
@@ -1450,13 +1459,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1450
1459
|
|
|
1451
1460
|
const changed = await this.system.flush(batch, this._workingBee)
|
|
1452
1461
|
|
|
1453
|
-
if (this._reindexed && (await this._isReindexed()))
|
|
1454
|
-
this._reindexed = false
|
|
1455
|
-
await this.local.setUserData(
|
|
1456
|
-
'autobee/head',
|
|
1457
|
-
encoding.encodeBootRecord(this.system.bootRecord())
|
|
1458
|
-
)
|
|
1459
|
-
}
|
|
1462
|
+
if (this._reindexed && (await this._isReindexed())) this._reindexed = false
|
|
1460
1463
|
|
|
1461
1464
|
if (this.system.promotions.changed) this._prefetchApprovals().catch(safetyCatch)
|
|
1462
1465
|
|