Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _processOne (entry) {
const hash = entry.hash || entry
if (this._store._oplog.has(hash) || this._fetching[hash]) {
return
}
this._fetching[hash] = hash
this.emit('load.added', entry)
this._stats.tasksStarted += 1
const exclude = []
const log = await Log.fromEntryHash(this._store._ipfs, this._store.identity, hash, { logId: this._store._oplog.id, access: this._store.access, length: batchSize, exclude })
this._buffer.push(log)
const latest = log.values[0]
delete this._queue[hash]
// Mark this task as processed
this._stats.tasksProcessed += 1
// Notify subscribers that we made progress
this.emit('load.progress', this._id, hash, latest, null, this._buffer.length)
// Return all next pointers
return log.values.map(getNext).reduce(flatMap, [])
}
}
async _processOne (entry) {
const hash = entry.hash || entry
if (this._store._oplog.has(hash) || this._fetching[hash])
return
this._fetching[hash] = hash
this.emit('load.added', entry)
this._stats.tasksStarted += 1
const exclude = []
const log = await Log.fromEntryHash(this._store._ipfs, hash, this._store._oplog.id, batchSize, exclude, this._store.key, this._store.access.write)
this._buffer.push(log)
const latest = log.values[0]
delete this._queue[hash]
// Mark this task as processed
this._stats.tasksProcessed += 1
// Notify subscribers that we made progress
this.emit('load.progress', this._id, hash, latest, null, this._buffer.length)
// Return all next pointers
return log.values.map(getNext).reduce(flatMap, [])
}
}
if (this.options.onLoad) {
await this.options.onLoad(this)
}
const localHeads = await this._cache.get(this.localHeadsPath) || []
const remoteHeads = await this._cache.get(this.remoteHeadsPath) || []
const heads = localHeads.concat(remoteHeads)
if (heads.length > 0) {
this.events.emit('load', this.address.toString(), heads)
}
// Update the replication status from the heads
heads.forEach(h => this._recalculateReplicationMax(h.clock.time))
// Load the log
const log = await Log.fromEntryHash(this._ipfs, this.identity, heads.map(e => e.hash), {
logId: this._oplog.id,
access: this.access,
sortFn: this.options.sortFn,
length: amount,
exclude: this._oplog.values,
onProgressCallback: this._onLoadProgress.bind(this),
timeout: fetchEntryTimeout
})
// Join the log with the existing log
await this._oplog.join(log, amount)
// Update the index
if (heads.length > 0) {
await this._updateIndex()
}