diff --git a/src/main/glam/xtdb/span.clj b/src/main/glam/xtdb/span.clj index 807580b..5274d71 100644 --- a/src/main/glam/xtdb/span.clj +++ b/src/main/glam/xtdb/span.clj @@ -95,14 +95,11 @@ (gxe/deftx add-token [node span-id token-id] (xutil/add-join** node span-id :span/tokens token-id)) -;; Note: this should NOT be used more than once in a single transaction on a given span, or else its -;; deletion behavior will not work properly. -;; TODO: is this still true now that this is a tx fn? (declare remove-token**) (gxe/deftx remove-token [node span-id token-id] (let [base-txs (xutil/remove-join** node span-id :span/tokens token-id)] (if (= 1 (-> (gxe/entity node span-id) :span/tokens count)) - (into base-txs [(gxe/delete* span-id)]) + (into base-txs (delete** node span-id)) base-txs))) diff --git a/src/main/glam/xtdb/text.clj b/src/main/glam/xtdb/text.clj index c4e6186..c4fe998 100644 --- a/src/main/glam/xtdb/text.clj +++ b/src/main/glam/xtdb/text.clj @@ -34,14 +34,6 @@ ;; Mutations ---------------------------------------------------------------------- -(defn get-span-ids [node eid] - (map first (xt/q (xt/db node) - '{:find [?span] - :where [[?span :span/tokens ?tok] - [?tok :token/text ?txt]] - :in [?txt]} - eid))) - (defn get-token-ids [node eid] (map first (xt/q (xt/db node) '{:find [?tok] @@ -63,13 +55,9 @@ tx (reduce into [text-tx deletion-tx update-tx])] tx)) -;; We don't follow the usual pattern of relying on child nodes' delete** functions here because -;; this would lead to children being included multiple times. Instead, we write a bespoke fn. (gxe/deftx delete [node eid] - (let [span-deletes (mapv gxe/delete* (get-span-ids node eid)) - token-deletes (mapv gxe/delete* (get-token-ids node eid)) + (let [token-deletes (reduce into (mapv #(tok/delete** node %) (get-token-ids node eid))) text-delete [(gxe/delete* eid)]] (reduce into - [span-deletes - token-deletes + [token-deletes text-delete]))) diff --git a/src/main/glam/xtdb/token.clj b/src/main/glam/xtdb/token.clj index f88907a..a015816 100644 --- a/src/main/glam/xtdb/token.clj +++ b/src/main/glam/xtdb/token.clj @@ -176,8 +176,6 @@ (defn set-begin [node eid n] (set-extent node eid {:new-begin n})) (defn set-end [node eid n] (set-extent node eid {:new-end n})) -;; We don't follow the usual pattern of relying on child nodes' delete** functions here because -;; this would lead to children being included multiple times. Instead, we write a bespoke fn. (gxe/deftx delete [node eid] (let [spans (get-span-ids node eid)] (into