Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# edge-sync-server

## Unreleased

- fixed: Fixed call-stack overflow bug when calculating latest checkpoint.
7 changes: 4 additions & 3 deletions src/util/store/syncing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ const calculateLatestCheckpoint = (
// Remove any previous document versions being overwritten.
// If there exists versions that are lower or equal than the current
// checkpoint version, then the max is the previous version.
const previousVersion = Math.max(
0,
...document.versions.filter(version => version <= checkpoint.version)
const previousVersion = document.versions.reduce(
(max, version) =>
version <= checkpoint.version && version > max ? version : max,
0
)
// Add latest version and subtract previous version.
return sum + document.versions[0] - previousVersion
Expand Down
Loading