Skip to content

Commit 49d34f0

Browse files
Guillaume Chauiksim
Guillaume Chau
authored and
iksim
committed
perf(vuex): cache last replay result
1 parent 6569b21 commit 49d34f0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/vuex.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,15 @@ class VuexBackend {
460460
}
461461

462462
// Optimization: periodically cache snapshots
463-
if (i !== index && i % SharedData.cacheVuexSnapshotsEvery === 0) {
463+
if (i === index || (i % SharedData.cacheVuexSnapshotsEvery === 0)) {
464464
this.cacheStateSnapshot(i)
465465
}
466466
}
467467

468468
// Send final state after replay
469469
resultState = clone(this.store.state)
470+
471+
if (!isProd) console.log(`replayed ${index - stateSnapshot.index} mutation(s)`)
470472
}
471473

472474
this.lastState = resultState
@@ -501,10 +503,14 @@ class VuexBackend {
501503
state: clone(this.store.state),
502504
permanent
503505
})
506+
if (!isProd) console.log('cached snapshot', index)
504507
// Delete old cached snapshots
505508
if (this.stateSnapshotCache.filter(s => !s.permanent).length > SharedData.cacheVuexSnapshotsLimit) {
506509
const i = this.stateSnapshotCache.findIndex(s => !s.permanent)
507-
if (i !== -1) this.stateSnapshotCache.splice(i, 1)
510+
if (i !== -1) {
511+
if (!isProd) console.log('clean cached snapshot', this.stateSnapshotCache[i].index)
512+
this.stateSnapshotCache.splice(i, 1)
513+
}
508514
}
509515
}
510516

0 commit comments

Comments
 (0)