diff --git a/CHANGELOG.md b/CHANGELOG.md index 2292653c..2ad2feb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/datascript/storage.clj b/src/datascript/storage.clj index 5e7ece7f..b4b28258 100644 --- a/src/datascript/storage.clj +++ b/src/datascript/storage.clj @@ -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 diff --git a/test/datascript/test/storage.clj b/test/datascript/test/storage.clj index b53561c0..1c4cdb40 100644 --- a/test/datascript/test/storage.clj +++ b/test/datascript/test/storage.clj @@ -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"]])