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

Refactor deletion methods for span, token, text #34

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/main/glam/xtdb/span.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))


Expand Down
16 changes: 2 additions & 14 deletions src/main/glam/xtdb/text.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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])))
2 changes: 0 additions & 2 deletions src/main/glam/xtdb/token.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down