@@ -102,9 +102,7 @@ class Store {
102
102
}
103
103
this . _replicationStatus . queued -= logs . length
104
104
this . _replicationStatus . buffered = this . _replicator . _buffer . length
105
- this . _recalculateReplicationMax ( )
106
- this . _index . updateIndex ( this . _oplog )
107
- this . _recalculateReplicationProgress ( )
105
+ await this . _updateIndex ( )
108
106
// logger.debug(`<replicated>`)
109
107
this . events . emit ( 'replicated' , this . address . toString ( ) , logs . length )
110
108
} catch ( e ) {
@@ -200,12 +198,11 @@ class Store {
200
198
this . _recalculateReplicationMax ( head . clock . time )
201
199
let log = await Log . fromEntryHash ( this . _ipfs , head . hash , this . _oplog . id , amount , this . _oplog . values , this . key , this . access . write , this . _onLoadProgress . bind ( this ) )
202
200
await this . _oplog . join ( log , amount , this . _oplog . id )
203
- this . _recalculateReplicationProgress ( )
204
201
} )
205
202
206
203
// Update the index
207
204
if ( heads . length > 0 )
208
- this . _index . updateIndex ( this . _oplog )
205
+ await this . _updateIndex ( )
209
206
210
207
this . events . emit ( 'ready' , this . address . toString ( ) , this . _oplog . heads )
211
208
}
@@ -392,9 +389,7 @@ class Store {
392
389
if ( snapshotData ) {
393
390
const log = await Log . fromJSON ( this . _ipfs , snapshotData , - 1 , this . _key , this . access . write , 1000 , onProgress )
394
391
await this . _oplog . join ( log , - 1 , this . _oplog . id )
395
- this . _recalculateReplicationMax ( )
396
- this . _index . updateIndex ( this . _oplog )
397
- this . _recalculateReplicationProgress ( )
392
+ await this . _updateIndex ( )
398
393
this . events . emit ( 'replicated' , this . address . toString ( ) )
399
394
}
400
395
this . events . emit ( 'ready' , this . address . toString ( ) , this . _oplog . heads )
@@ -405,12 +400,18 @@ class Store {
405
400
return this
406
401
}
407
402
403
+ async _updateIndex ( ) {
404
+ this . _recalculateReplicationMax ( )
405
+ await this . _index . updateIndex ( this . _oplog )
406
+ this . _recalculateReplicationProgress ( )
407
+ }
408
+
408
409
async _addOperation ( data , batchOperation , lastOperation , onProgressCallback ) {
409
410
if ( this . _oplog ) {
410
411
const entry = await this . _oplog . append ( data , this . options . referenceCount )
411
412
this . _recalculateReplicationStatus ( this . replicationStatus . progress + 1 , entry . clock . time )
412
413
await this . _cache . set ( '_localHeads' , [ entry ] )
413
- this . _index . updateIndex ( this . _oplog )
414
+ await this . _updateIndex ( )
414
415
this . events . emit ( 'write' , this . address . toString ( ) , entry , this . _oplog . heads )
415
416
if ( onProgressCallback ) onProgressCallback ( entry )
416
417
return entry . hash
0 commit comments