hypercore-storage 2.5.0 → 2.5.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.
Files changed (2) hide show
  1. package/index.js +16 -11
  2. 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,34 @@ 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 view = await this._enter()
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.getInfos(keys, { auth: false, head: false, hints: true })
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
  }
826
+ tx.apply()
825
827
  } finally {
826
- await this._exit()
828
+ if (own) await this._exit()
827
829
  }
828
830
  }
829
831
 
@@ -902,9 +904,12 @@ class CorestoreStorage {
902
904
  return (await this.getInfos([discoveryKey], opts))[0]
903
905
  }
904
906
 
905
- async getInfos(discoveryKeys, { auth = true, head = true, hints = true } = {}) {
907
+ async getInfos(discoveryKeys, opts) {
906
908
  if (this.version === 0) await this._migrateStore()
909
+ return this._getInfos(discoveryKeys, opts)
910
+ }
907
911
 
912
+ async _getInfos(discoveryKeys, { auth = true, head = true, hints = true } = {}) {
908
913
  const rx = new CorestoreRX(this.db, EMPTY)
909
914
  const corePromises = new Array(discoveryKeys.length)
910
915
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",