You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
http-kit and compojure benchmarks have incorrect behavior #1979
The code in this function is incorrect. The result of the for is never used, and since for is lazy, it's never even evaluated. So, no database updates are actually happening. In fact, the update-in function would throw an error in this example if it ran, since it expects a function.
(defnupdate-and-persist-raw"Using JDBC: Changes the :randomNumber of a number of world entities. Persists the changes to sql then returns the updated entities"
[queries]
(let [results (run-queries queries)]
(for [w results]
(update-in w [:randomNumber (inc (rand-int9999))]
(jdbc/update! (db-mysql-raw) :world {:randomNumber (:randomNumber w)} ["id = ?" (:id w)])))
results))
A correct function would look something like the following, where doseq is used to force evaluation of writing the queries to the database.
(defnupdate-and-persist-raw"Using JDBC: Changes the :randomNumber of a number of world entities. Persists the changes to sql then returns the updated entities"
[queries]
(let [results (run-queries queries)]
(let [world (map #(assoc % :randomNumber (inc (rand-int9999))) (run-queries queries))]
(doseq [{:keys [id randomNumber]} world]
(jdbc/update! (db-mysql-raw) :world {:randomNumber randomNumber} ["id = ?" id w]))
world)))
I think this also highlights a gap in the tests. The test suite should check that the values in the database match those returned by the service.
@yogthos Good catch! I don't think I'll be able to get to this today. If you'd like to submit a fix it would be very welcome. Otherwise I'll get to it as soon as I can.
Activity
k-r-g commentedon Mar 18, 2016
@yogthos Good catch! I don't think I'll be able to get to this today. If you'd like to submit a fix it would be very welcome. Otherwise I'll get to it as soon as I can.
yogthos commentedon Mar 18, 2016
Sure thing, if I get some cycles before you do, I'll pr for this.
k-r-g commentedon Apr 15, 2016
@yogthos What do you think of my fix in #2026? I believe this addresses the problem.
yogthos commentedon Apr 15, 2016
Yeah that looks like it should do it. 👍
NateBrady23 commentedon Aug 31, 2016
Looks like this has been resolved.