Skip to content

Commit

Permalink
skip map
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Oct 7, 2024
1 parent 3811937 commit f7fa008
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions lib/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1836,34 +1836,18 @@ module.exports = class Replicator {
async _resolveBlocksLocally () {
// TODO: check if fork compat etc. Requires that we pass down truncation info

let clear = null
const clear = []
const blocks = []

const reader = this.core.storage.createReadBatch()

const blocks = new Map()
for (const b of this._blocks) {
if (this.core.bitfield.get(b.index) === false) continue

const request = this.core.blocks.get(reader, b.index)
blocks.set(b, request)

request.catch(safetyCatch) // safety catch in meantime
blocks.push(this._resolveLocalBlock(b, reader, clear))
}

reader.tryFlush()

for (const [b, request] of blocks) {
try {
b.resolve(await request)
} catch (err) {
b.reject(err)
}

if (clear === null) clear = []
clear.push(b)
}
await Promise.all(blocks)

if (clear === null) return
if (!clear.length) return

// Currently the block tracker does not support deletes during iteration, so we make
// sure to clear them afterwards.
Expand All @@ -1872,6 +1856,19 @@ module.exports = class Replicator {
}
}

async _resolveLocalBlock (b, reader, resolved) {
if (this.core.bitfield.get(b.index) === false) return

try {
b.resolve(await this.core.blocks.get(reader, b.index))
} catch (err) {
b.reject(err)
return
}

resolved.push(b)
}

_resolveBlockRequest (tracker, index, value, req) {
const b = tracker.remove(index)
if (b === null) return false
Expand Down

0 comments on commit f7fa008

Please sign in to comment.