Skip to content

Commit d270292

Browse files
committed
Correctly restore :max-tx from storage
1 parent d67931b commit d270292

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# WIP
22

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

56
# 1.6.5 - May 3, 2024
67

src/datascript/storage.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@
152152
(defn db-with-tail [db tail]
153153
(reduce
154154
(fn [db datoms]
155-
(reduce db/with-datom db datoms))
155+
(if (empty? datoms)
156+
db
157+
(as-> db %
158+
(reduce db/with-datom % datoms)
159+
(assoc % :max-tx (:tx (first datoms))))))
156160
db tail))
157161

158162
(defn restore

test/datascript/test/storage.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@
272272
;; restore conn with tail
273273
(let [conn' (d/restore-conn storage)]
274274
(is (= @conn @conn'))
275+
(is (= (:max-eid @conn) (:max-eid @conn')))
276+
(is (= (:max-tx @conn) (:max-tx @conn')))
275277

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

0 commit comments

Comments
 (0)