Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 1e3d55d

Browse files
authored
Merge pull request #28 from crazybuster/cache-verified
Cache verified heads only.
2 parents 931c452 + dd597fe commit 1e3d55d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Store.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class Store {
106106
this._replicationStatus.queued -= logs.length
107107
this._replicationStatus.buffered = this._replicator._buffer.length
108108
await this._updateIndex()
109+
110+
//only store heads that has been verified and merges
111+
const heads = this._oplog.heads
112+
await this._cache.set('_remoteHeads', heads)
113+
logger.debug(`Saved heads ${heads.length} [${heads.map(e => e.hash).join(', ')}]`)
114+
109115
// logger.debug(`<replicated>`)
110116
this.events.emit('replicated', this.address.toString(), logs.length)
111117
} catch (e) {
@@ -256,9 +262,7 @@ class Store {
256262

257263
return mapSeries(heads, saveToIpfs)
258264
.then(async (saved) => {
259-
await this._cache.set('_remoteHeads', heads)
260-
logger.debug(`Saved heads ${heads.length} [${saved.map(e => e.hash).join(', ')}]`)
261-
return this._replicator.load(saved.filter(e => e !== null))
265+
return this._replicator.load(saved.filter(e => e !== null))
262266
})
263267
}
264268

0 commit comments

Comments
 (0)