I’m a clojure and xtdb n00b, but I’ve come up with this functionality, and I’d like some feedback.
Is this a reasonable way to update the record only if it’s changed? Some documents may be over 1Mb in size.
It’s working thus far, but I want to make sure I’m not setting myself for failure down the road.
POST /_xtdb/submit-tx
{
"tx-ops": [
[
"put",
{
"xt/id": "hash",
"xt/fn": "(fn [m] (hash (into (sorted-map) m)))"
}
]
[
"put",
{
"xt/id": "update-if-different",
"xt/fn":"
(fn [ctx new-entity]
(if (not= (hash new-entity)
(hash (xtdb.api/entity
(xtdb.api/db ctx)
(get new-entity :xt/id))))
[[:xtdb.api/put new-entity]]
)
)"
}
]
]
}
POST /_xtdb/submit-tx
{
"tx-ops": [
[ "fn" => "update-if-different", { "xt/id" => "555555", name => "bruh"}]
]
}