replikativ / datahike

A fast, immutable, distributed & compositional Datalog engine for everyone.
https://datahike.io
Eclipse Public License 1.0
1.63k stars 97 forks source link

[Bug](?): Transact result :tx-data no longer shows only changed datoms #457

Open spieden opened 2 years ago

spieden commented 2 years ago

What version of Datahike are you using?

0.4.1473

What version of Java are you using?

11.0.12

What operating system are you using?

Linux

What database EDN configuration are you using?

(def config
    {:schema-flexibility :read
     :store {:backend :file
             :path (.getAbsolutePath file)}})

Describe the bug

I have a previous project using datahike version 0.2.1. In this project when I transact the exact same transaction twice in a row, :tx-data is empty except for the transaction entity the second time around. i.e. It only shows me what has changed as a result of the transaction. This is super useful, as I can use datahike to produce diffs for me of previous vs new DB state!

Now I'm starting a new project using the latest version and this behavior is gone. It shows me all datums every time even when they are noops.

Is this intentional? I really liked the old behavior. :)

Awesome project, BTW!

Example:

0.2.1

shazoom.db=> (clojure.pprint/pprint (d/transact (conn) [[:db/add 2 :foo :bar]]))
{:db-before
 #datahike/DB {:schema ...}
 :db-after
 #datahike/DB {:schema ...},
 :tx-data
 [#datahike/Datom [536871450
                   :db/txInstant
                   #inst "2021-12-16T00:46:05.195-00:00"
                   536871450]
  #datahike/Datom [2 :foo :bar 536871450]],
 :tempids #:db{:current-tx 536871450},
 :tx-meta nil}
nil
shazoom.db=> (clojure.pprint/pprint (d/transact (conn) [[:db/add 2 :foo :bar]]))
{:db-before
 #datahike/DB {:schema ...},
 :tx-data
 [#datahike/Datom [536871451
                   :db/txInstant
                   #inst "2021-12-16T00:46:07.024-00:00"
                   536871451]],
 :tempids #:db{:current-tx 536871451},
 :tx-meta nil}
nil

0.4.1473

user=> (clojure.pprint/pprint (db/transact [[:db/add 1 :foo :bar]]))
{:db-before #datahike/DB {:max-tx 536871012 :max-eid 678},
 :db-after #datahike/DB {:max-tx 536871013 :max-eid 678},
 :tx-data
 [#datahike/Datom [536871013
                   :db/txInstant
                   #inst "2021-12-16T00:38:34.750-00:00"
                   536871013]
  #datahike/Datom [1 :foo :bar 536871013]],
 :tempids #:db{:current-tx 536871013},
 :tx-meta nil}
nil
user=> (clojure.pprint/pprint (db/transact [[:db/add 1 :foo :bar]]))
{:db-before #datahike/DB {:max-tx 536871013 :max-eid 678},
 :db-after #datahike/DB {:max-tx 536871014 :max-eid 678},
 :tx-data
 [#datahike/Datom [536871014
                   :db/txInstant
                   #inst "2021-12-16T00:38:38.672-00:00"
                   536871014]
  #datahike/Datom [1 :foo :bar 536871014]],
 :tempids #:db{:current-tx 536871014},
 :tx-meta nil}
nil

What is the expected behaviour?

Only changed datums shown in :tx-data

How can the behaviour be reproduced?

Transact the same transaction twice and observe datums are same both times

kordano commented 2 years ago

Thanks for reporting that. We'll take a look. Might be connected to #365