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

Commit

Permalink
load before append
Browse files Browse the repository at this point in the history
  • Loading branch information
shamb0t committed Jul 8, 2019
1 parent 85cc685 commit 752e4bf
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 58 deletions.
139 changes: 83 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const DefaultOptions = {
directory: './orbitdb',
replicate: true,
referenceCount: 64,
replicationConcurrency: 128
replicationConcurrency: 128,
syncLocal: false
}

class Store {
Expand Down Expand Up @@ -200,7 +201,6 @@ class Store {
async load (amount) {
amount = amount || this.options.maxHistory


const localHeads = await this._cache.get('_localHeads') || []
const remoteHeads = await this._cache.get('_remoteHeads') || []
const heads = localHeads.concat(remoteHeads)
Expand Down Expand Up @@ -419,6 +419,12 @@ class Store {

async _addOperation (data, batchOperation, lastOperation, onProgressCallback) {
if (this._oplog) {
if (this.options.syncLocal) {
const localHeads = await this._cache.get('_localHeads') || []
if (localHeads[0] && localHeads[0].hash != this._oplog.heads[0]) {
await this.load()
}
}
const entry = await this._oplog.append(data, this.options.referenceCount)
this._recalculateReplicationStatus(this.replicationStatus.progress + 1, entry.clock.time)
await this._cache.set('_localHeads', [entry])
Expand Down

0 comments on commit 752e4bf

Please sign in to comment.