Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip data deconstruction for :db/ident #2

Open
quoll opened this issue Aug 5, 2020 · 1 comment
Open

Skip data deconstruction for :db/ident #2

quoll opened this issue Aug 5, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@quoll
Copy link
Contributor

quoll commented Aug 5, 2020

If a seqable value is passed as a :db/ident value, then this is currently deconstructed into a linked list. Skip this operation for the :db/ident property only.

@quoll quoll assigned quoll and unassigned quoll Aug 5, 2020
@quoll quoll added the enhancement New feature or request label Aug 5, 2020
@quoll
Copy link
Contributor Author

quoll commented Aug 6, 2020

The constructed triples appear this way:

cljs.user=> (def tx (d/transact conn {:tx-data [{:db/ident ["liz" 5] :name "Elizabeth"}]}))
#'cljs.user/tx
cljs.user=> (pprint (:tx-data @tx))
([:tg/node-5 :tg/entity true 3 true]
 [:tg/node-5 :db/ident :tg/node-6 3 true]
 [:tg/node-6 :tg/first "liz" 3 true]
 [:tg/node-6 :tg/rest :tg/node-7 3 true]
 [:tg/node-7 :tg/first 5 3 true]
 [:tg/node-6 :tg/contains "liz" 3 true]
 [:tg/node-6 :tg/contains 5 3 true]
 [:tg/node-5 :name "Elizabeth" 3 true])

Instead, what we want here is the following:

([:tg/node-5 :tg/entity true 3 true]
 [:tg/node-5 :db/ident ["liz" 3] 3 true]
 [:tg/node-5 :name "Elizabeth" 3 true])

This happens in zuko.entity.writer/property-vals. This function is called for every attribute/value pair, and generates the following:

  1. If the value is a set, then that means that the attribute is reused for multiple values. For each value in the set, the following steps will occur for each attribute/value. (The implementor can ignore this).
  2. If the value is a simple scalar, then the value will be that scalar.
  3. If the value represent a structure, then allocated a node to represent the structure, and create a sequence of triples that use that node to represent the structure. The value will now be this node.
  4. Cons the above sequence a single triple of the form [ entity-id attribute value ]

Steps 2 and 3 occur are performed by the function value-triples. The return value from this function is nested via an if-let due to defensive programming (I think an interface changed at some point), but in fact the value-triples function can never return nil. The if-let should probably be updated to a simple let.

@quoll quoll assigned quoll and unassigned quoll Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant