hypercore-storage 2.5.0 → 2.5.1
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 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -547,10 +547,10 @@ class CorestoreStorage {
|
|
|
547
547
|
}
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
async _maybeRecover() {
|
|
550
|
+
async _maybeRecover(view) {
|
|
551
551
|
const r = path.join(this.db.path, 'RECOVERING')
|
|
552
552
|
if (!(await fileExists(r))) return
|
|
553
|
-
await this.setRecovering()
|
|
553
|
+
await this.setRecovering(view)
|
|
554
554
|
await fs.promises.unlink(r)
|
|
555
555
|
}
|
|
556
556
|
|
|
@@ -578,7 +578,7 @@ class CorestoreStorage {
|
|
|
578
578
|
throw err
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
-
await this._maybeRecover()
|
|
581
|
+
await this._maybeRecover(view)
|
|
582
582
|
|
|
583
583
|
const rx = new CorestoreRX(this.db, view)
|
|
584
584
|
const headPromise = rx.getHead()
|
|
@@ -798,32 +798,33 @@ class CorestoreStorage {
|
|
|
798
798
|
}
|
|
799
799
|
}
|
|
800
800
|
|
|
801
|
-
async setRecovering() {
|
|
801
|
+
async setRecovering(view = null) {
|
|
802
802
|
const recovering = Date.now()
|
|
803
803
|
let keys = []
|
|
804
804
|
|
|
805
805
|
for await (const data of this.createDiscoveryKeyStream()) {
|
|
806
806
|
keys.push(data)
|
|
807
807
|
if (keys.length > 16 * 1024) {
|
|
808
|
-
await this._flushRecovering(recovering, keys)
|
|
808
|
+
await this._flushRecovering(recovering, view, keys)
|
|
809
809
|
keys = []
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
-
if (keys.length) await this._flushRecovering(recovering, keys)
|
|
813
|
+
if (keys.length) await this._flushRecovering(recovering, view, keys)
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
async _flushRecovering(recovering, keys) {
|
|
817
|
-
const
|
|
816
|
+
async _flushRecovering(recovering, view, keys) {
|
|
817
|
+
const own = !view
|
|
818
|
+
if (own) view = await this._enter()
|
|
818
819
|
const tx = new CorestoreTX(view)
|
|
819
820
|
|
|
820
821
|
try {
|
|
821
|
-
const infos = await this.
|
|
822
|
+
const infos = await this._getInfos(keys, { auth: false, head: false, hints: true })
|
|
822
823
|
for (const inf of infos) {
|
|
823
824
|
tx.setCoreHints(inf.core, { ...inf.hints, recovering })
|
|
824
825
|
}
|
|
825
826
|
} finally {
|
|
826
|
-
await this._exit()
|
|
827
|
+
if (own) await this._exit()
|
|
827
828
|
}
|
|
828
829
|
}
|
|
829
830
|
|
|
@@ -902,9 +903,12 @@ class CorestoreStorage {
|
|
|
902
903
|
return (await this.getInfos([discoveryKey], opts))[0]
|
|
903
904
|
}
|
|
904
905
|
|
|
905
|
-
async getInfos(discoveryKeys,
|
|
906
|
+
async getInfos(discoveryKeys, opts) {
|
|
906
907
|
if (this.version === 0) await this._migrateStore()
|
|
908
|
+
return this._getInfos(discoveryKeys, opts)
|
|
909
|
+
}
|
|
907
910
|
|
|
911
|
+
async _getInfos(discoveryKeys, { auth = true, head = true, hints = true } = {}) {
|
|
908
912
|
const rx = new CorestoreRX(this.db, EMPTY)
|
|
909
913
|
const corePromises = new Array(discoveryKeys.length)
|
|
910
914
|
|