From 81d41a442d8b75821400b949691c8ec1efa1a25f Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Fri, 5 Apr 2019 17:35:43 +0200 Subject: [PATCH] perf(vuex): cache last replay result --- src/backend/vuex.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/vuex.js b/src/backend/vuex.js index 178b0d7..3722f6f 100644 --- a/src/backend/vuex.js +++ b/src/backend/vuex.js @@ -460,13 +460,15 @@ class VuexBackend { } // Optimization: periodically cache snapshots - if (i !== index && i % SharedData.cacheVuexSnapshotsEvery === 0) { + if (i === index || (i % SharedData.cacheVuexSnapshotsEvery === 0)) { this.cacheStateSnapshot(i) } } // Send final state after replay resultState = clone(this.store.state) + + if (!isProd) console.log(`replayed ${index - stateSnapshot.index} mutation(s)`) } this.lastState = resultState @@ -501,10 +503,14 @@ class VuexBackend { state: clone(this.store.state), permanent }) + if (!isProd) console.log('cached snapshot', index) // Delete old cached snapshots if (this.stateSnapshotCache.filter(s => !s.permanent).length > SharedData.cacheVuexSnapshotsLimit) { const i = this.stateSnapshotCache.findIndex(s => !s.permanent) - if (i !== -1) this.stateSnapshotCache.splice(i, 1) + if (i !== -1) { + if (!isProd) console.log('clean cached snapshot', this.stateSnapshotCache[i].index) + this.stateSnapshotCache.splice(i, 1) + } } } -- GitLab