Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
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

Closed

Description

@yogthos

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.

(defn update-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-int 9999))]
        (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.

(defn update-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-int 9999))) (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.

Activity

  1. k-r-g commented on Mar 18, 2016

    @k-r-g
    Contributor

    @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.

  2. yogthos commented on Mar 18, 2016

    @yogthos
    ContributorAuthor

    Sure thing, if I get some cycles before you do, I'll pr for this.

  3. k-r-g commented on Apr 15, 2016

    @k-r-g
    Contributor

    @yogthos What do you think of my fix in #2026? I believe this addresses the problem.

  4. yogthos commented on Apr 15, 2016

    @yogthos
    ContributorAuthor

    Yeah that looks like it should do it. 👍

  5. NateBrady23 commented on Aug 31, 2016

    @NateBrady23
    Member

    Looks like this has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions