Skip to content

Commit

Permalink
no need to load head now
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Oct 16, 2024
1 parent 43b6cc4 commit 483304a
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,11 @@ class HypercoreStorage {
const existing = await this.db.get(encodeBatch(this.corePointer, CORE.BATCHES, name))
if (!existing) return null

const read = this.createReadBatch()
const headPromise = read.getCoreHead()

read.tryFlush()

const head = await headPromise

const storage = new HypercoreStorage(this.root, this.discoveryKey, this.corePointer, this.dataPointer, this.dbSnapshot)
const dataPointer = c.decode(m.DataPointer, existing)

storage.dataPointer = dataPointer
storage.dependencies = await addDependencies(this.db, storage.dataPointer, head ? head.length : 0)
storage.dependencies = await addDependencies(this.db, storage.dataPointer, -1)

return storage
}
Expand Down Expand Up @@ -720,7 +713,7 @@ async function addDependencies (db, dataPointer, treeLength) {
let dep = await db.get(encodeDataIndex(dataPointer, DATA.DEPENDENCY))
while (dep) {
const { data, length } = c.decode(m.DataDependency, dep)
if (length <= treeLength) dependencies.push({ data, length })
if (treeLength === -1 || length <= treeLength) dependencies.push({ data, length })

dep = await db.get(encodeDataIndex(data, DATA.DEPENDENCY))
}
Expand Down

0 comments on commit 483304a

Please sign in to comment.