Skip to content

Commit 4b1f15f

Browse files
committed
fix: exclude datoms from tail if already exists and not retracted
1 parent 5e33440 commit 4b1f15f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/datascript/storage.cljs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@
158158
:max-eid max-eid
159159
:max-tx max-tx})]
160160
(remember-db db)
161-
[db (mapv #(keep (fn [[e a v tx added]]
161+
[db (mapv #(keep (fn [[e a v tx]]
162162
;; fix unique constraint
163-
(let [datom-exists? (some? (db/-datoms db :eavt e a v nil))]
164-
(when-not (and datom-exists? added)
165-
(db/datom e a v tx added)))) %)
163+
(let [datom-exists? (some? (db/-datoms db :eavt e a v nil))
164+
;; retracted tx < 0
165+
added? (> tx 0)]
166+
(when-not (and datom-exists? added?)
167+
(db/datom e a v tx)))) %)
166168
tail)]))))
167169

168170
(defn db-with-tail [db tail]

0 commit comments

Comments
 (0)