Skip to content

Commit

Permalink
catchup triggers drain to flush indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Jun 13, 2024
1 parent 12ba775 commit 3f1afbd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ module.exports = class Autobase extends ReadyResource {
}
}

await this._gcWriters()
await this._drain() // runs for one tick
}

_reindexersIdle () {
Expand Down Expand Up @@ -1162,7 +1162,7 @@ module.exports = class Autobase extends ReadyResource {

async _drain () {
while (!this.closing) {
if (this.fastForwardTo !== null) {
if (this.opened && this.fastForwardTo !== null) {
await this._applyFastForward()
this.system.requestWakeup()
}
Expand All @@ -1172,8 +1172,8 @@ module.exports = class Autobase extends ReadyResource {
await this._loadLocalWriter(this.system)
}

const remoteAdded = await this._addRemoteHeads()
const localNodes = this._appending === null ? null : this._addLocalHeads()
const remoteAdded = this.opened ? await this._addRemoteHeads() : null
const localNodes = this.opened && this._appending !== null ? this._addLocalHeads() : null

if (this._maybeStaticFastForward === true && this.fastForwardEnabled === true) await this._checkStaticFastForward()
if (this.closing) return
Expand Down Expand Up @@ -1216,6 +1216,7 @@ module.exports = class Autobase extends ReadyResource {
if (!changed) {
if (this._checkWriters.length > 0) {
await this._gcWriters()
if (!this.opened) break // at most one tick preready
continue // rerun the update loop as a writer might have been added
}
if (remoteAdded >= REMOTE_ADD_BATCH) continue
Expand Down

0 comments on commit 3f1afbd

Please sign in to comment.