hypercore-storage 0.0.38 → 0.0.39
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/lib/memory-overlay.js +5 -5
- package/package.json +1 -1
package/lib/memory-overlay.js
CHANGED
|
@@ -117,7 +117,7 @@ class MemoryOverlay {
|
|
|
117
117
|
this.snapshotted = false
|
|
118
118
|
this.snapshotShared = null
|
|
119
119
|
this.activeSnapshots = 0
|
|
120
|
-
this.
|
|
120
|
+
this.copied = false
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
async registerBatch (name, length, overwrite) {
|
|
@@ -128,7 +128,6 @@ class MemoryOverlay {
|
|
|
128
128
|
if (this.snapshotShared !== null) return this.snapshotShared.snapshot()
|
|
129
129
|
|
|
130
130
|
this.activeSnapshots++
|
|
131
|
-
this.copyOnWrite = true
|
|
132
131
|
|
|
133
132
|
const snap = new MemoryOverlay(this.storage.snapshot())
|
|
134
133
|
|
|
@@ -150,7 +149,8 @@ class MemoryOverlay {
|
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
_copy () {
|
|
153
|
-
this.
|
|
152
|
+
if (this.copied) return
|
|
153
|
+
this.copied = true
|
|
154
154
|
|
|
155
155
|
// clone state
|
|
156
156
|
if (this.head !== null) this.head = Object.assign(this.head)
|
|
@@ -179,7 +179,7 @@ class MemoryOverlay {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
createWriteBatch () {
|
|
182
|
-
if (this.
|
|
182
|
+
if (this.activeSnapshots > 0) this._copy()
|
|
183
183
|
return new MemoryOverlayWriteBatch(this)
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -222,7 +222,7 @@ class MemoryOverlay {
|
|
|
222
222
|
destroy () {
|
|
223
223
|
if (this.snapshotted) this.storage.destroy()
|
|
224
224
|
if (this.snapshotShared === null) return
|
|
225
|
-
|
|
225
|
+
this.snapshotShared.activeSnapshots--
|
|
226
226
|
this.snapshotShared = null
|
|
227
227
|
}
|
|
228
228
|
|