Skip to content

Commit

Permalink
Correctly restore :max-tx from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed May 23, 2024
1 parent d67931b commit d270292
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# WIP

- Stable sorting of sequences of various types #470
- Correctly restore `:max-tx` from storage

# 1.6.5 - May 3, 2024

Expand Down
6 changes: 5 additions & 1 deletion src/datascript/storage.clj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@
(defn db-with-tail [db tail]
(reduce
(fn [db datoms]
(reduce db/with-datom db datoms))
(if (empty? datoms)
db
(as-> db %
(reduce db/with-datom % datoms)
(assoc % :max-tx (:tx (first datoms))))))
db tail))

(defn restore
Expand Down
2 changes: 2 additions & 0 deletions test/datascript/test/storage.clj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
;; restore conn with tail
(let [conn' (d/restore-conn storage)]
(is (= @conn @conn'))
(is (= (:max-eid @conn) (:max-eid @conn')))
(is (= (:max-tx @conn) (:max-tx @conn')))

;; transact keeps working on restored conn
(d/transact! conn' [[:db/add 35 :name "Vera"]])
Expand Down

0 comments on commit d270292

Please sign in to comment.