Skip to content

Commit

Permalink
[jdbc.read] Don't track realized keys in TransientRow
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev committed Oct 5, 2024
1 parent 86929ea commit 935cd72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
17 changes: 3 additions & 14 deletions src/toucan2/jdbc/row.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
;; a function that given a column name key will normalize it and return the
;; corresponding JDBC index. This should probably be memoized for the whole result set.
column-name->index
;; an atom with a set of realized column name keywords.
realized-keys
;; ATOM with map. Given a JDBC column index (starting at 1) return a thunk that can be
;; used to fetch the column. This usually comes
;; from [[toucan2.jdbc.read/make-cached-i->thunk]].
Expand All @@ -74,7 +72,6 @@
(if (realized? realized-row)
(assoc @realized-row k v)
(let [^clojure.lang.ITransientMap transient-row' (assoc! transient-row k v)]
(swap! realized-keys conj k)
(assert (= (.valAt transient-row' k) v)
(format "assoc! did not do what we expected. k = %s v = %s row = %s .valAt = %s"
(pr-str k)
Expand All @@ -90,7 +87,6 @@
rset
builder
column-name->index
realized-keys
i->thunk
transient-row'
realized-row)))))
Expand Down Expand Up @@ -118,7 +114,6 @@
(if (= index k-index)
(constantly ::not-found)
(i->thunk index))))))
(swap! realized-keys disj k)
;; as in the `assoc` method above, we can optimize a bit and return `this` instead of creating a new object if
;; `assoc!` returned the original `transient-row` rather than a different object
(if (and (identical? transient-row transient-row')
Expand All @@ -128,7 +123,6 @@
rset
builder
column-name->index'
realized-keys
i->thunk
transient-row'
realized-row)))))
Expand Down Expand Up @@ -295,12 +289,9 @@
'transient' mode."
[^toucan2.jdbc.row.TransientRow row]
(try
(let [transient-row (.transient_row row)
realized-keys (.realized_keys row)]
(let [transient-row (.transient_row row)]
[(symbol (format "^%s " `TransientRow))
;; (instance? pretty.core.PrettyPrintable transient-row) (pretty/pretty transient-row)
(zipmap @realized-keys
(map #(get transient-row %) @realized-keys))])
(persistent! transient-row)])
(catch Exception _
["unrealized result set {row} -- do you need to call toucan2.realize/realize ?"])))

Expand Down Expand Up @@ -361,14 +352,12 @@
(assert (not (.isClosed rset)) "ResultSet is already closed")
(let [transient-row (next.jdbc.rs/->row builder)
i->thunk (atom i->thunk)
realized-row-delay (make-realized-row-delay builder i->thunk transient-row)
realized-keys (atom #{})]
realized-row-delay (make-realized-row-delay builder i->thunk transient-row)]
;; this is a gross amount of positional args. But using `reify` makes debugging things too hard IMO.
(->TransientRow model
rset
builder
col-name->index
realized-keys
i->thunk
transient-row
realized-row-delay)))
13 changes: 0 additions & 13 deletions test/toucan2/jdbc/row_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
conj
(select/reducible-select ::test/venues 1)))))

(defn- realized-keys [^TransientRow row]
@(.realized_keys row))

(defn- already-realized? [^TransientRow row]
(realized? (.realized_row row)))

Expand All @@ -49,8 +46,6 @@
(get row :xyz)))
(is (= ::not-found
(get row :xyz ::not-found)))
(is (= #{:name}
(realized-keys row)))
(is (not (already-realized? row))))))

(deftest ^:parallel assoc-test
Expand All @@ -66,8 +61,6 @@
(:k row)))
(testing "namespaced key"
(is (transient-row? (assoc row :namespaced/k 500)))
(is (= #{:k :namespaced/k}
(realized-keys row)))
(is (contains? row :k))
(is (contains? row :namespaced/k))
(is (not (already-realized? row)))
Expand All @@ -93,8 +86,6 @@
(do-with-row
(fn [row]
(is (transient-row? (assoc row :k nil)))
(is (= #{:k}
(realized-keys row)))
(is (not (already-realized? row)))
(is (= nil
(get row :k)
Expand All @@ -107,17 +98,13 @@
(fn [row]
(let [row' (merge row {:k 1000})]
(doseq [row [row row']]
(is (= #{:k}
(realized-keys row)))
(is (not (already-realized? row))))))))

(deftest ^:parallel contains?-test
(do-with-row
(fn [row]
(is (contains? row :name))
(is (not (contains? row :xyz)))
(is (= #{}
(realized-keys row)))
(is (not (already-realized? row))))))

(deftest ^:parallel deferrable-update-test
Expand Down

0 comments on commit 935cd72

Please sign in to comment.