hypercore-storage 1.8.0 → 1.8.2
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 +15 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -101,7 +101,7 @@ class HypercoreStorage {
|
|
|
101
101
|
return null
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
setDependencyHead (dep) {
|
|
105
105
|
const deps = this.core.dependencies
|
|
106
106
|
|
|
107
107
|
for (let i = deps.length - 1; i >= 0; i--) {
|
|
@@ -123,6 +123,11 @@ class HypercoreStorage {
|
|
|
123
123
|
length: dep.length
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
this.core.dependencies = [{
|
|
128
|
+
dataPointer: dep.dataPointer,
|
|
129
|
+
length: dep.length
|
|
130
|
+
}]
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
// TODO: this might have to be async if the dependents have changed, but prop ok for now
|
|
@@ -247,8 +252,9 @@ class HypercoreStorage {
|
|
|
247
252
|
|
|
248
253
|
const sessions = existingSessions || []
|
|
249
254
|
const session = getBatch(sessions, name, true)
|
|
255
|
+
const fresh = session.dataPointer === -1
|
|
250
256
|
|
|
251
|
-
if (
|
|
257
|
+
if (fresh) {
|
|
252
258
|
session.dataPointer = await this.store._allocData()
|
|
253
259
|
}
|
|
254
260
|
|
|
@@ -268,6 +274,13 @@ class HypercoreStorage {
|
|
|
268
274
|
if (length > 0) coreTx.setHead(head)
|
|
269
275
|
coreTx.setDependency(core.dependencies[core.dependencies.length - 1])
|
|
270
276
|
|
|
277
|
+
if (!fresh) {
|
|
278
|
+
// nuke all existing state...
|
|
279
|
+
coreTx.deleteBlockRange(0, -1)
|
|
280
|
+
coreTx.deleteTreeNodeRange(0, -1)
|
|
281
|
+
coreTx.deleteBitfieldPageRange(0, -1)
|
|
282
|
+
}
|
|
283
|
+
|
|
271
284
|
await tx.flush()
|
|
272
285
|
|
|
273
286
|
return new HypercoreStorage(this.store, this.db.session(), core, this.atom ? this.view : new View(), this.atom)
|