Browse Source

fixes for routes

Yogthos 10 years ago
parent
commit
2599a7c890

+ 0 - 6
frameworks/Clojure/luminus/hello/resources/sql/queries.sql

@@ -17,10 +17,4 @@ WHERE id = :id
 -- query all fortune records
 SELECT id, message FROM fortune
 
---name: insert-world<!
--- create a world record
-INSERT into world
-(id, randomNumber)
-values (:id, :randomNumber)
-
 

+ 2 - 1
frameworks/Clojure/luminus/hello/src/hello/core.clj

@@ -1,5 +1,5 @@
 (ns hello.core
-  (:require [hello.handler :refer [app]]
+  (:require [hello.handler :refer [app init]]
             [clojure.tools.cli :refer [cli]]
             [org.httpkit.server :refer [run-server]])
   (:gen-class))
@@ -15,6 +15,7 @@
 (defn start-server [{:keys [port]}]
   (let [cpu (.availableProcessors (Runtime/getRuntime))]
     ;; double worker threads should increase database access performance
+    (init)
     (run-server app {:port port :thread (* 2 cpu)})
     (println (str "http-kit server listens at :" port))))
 

+ 6 - 6
frameworks/Clojure/luminus/hello/src/hello/db/core.clj

@@ -43,11 +43,6 @@
   []
   (get-world {:id (inc (rand-int 9999))} {:connection @db}))
 
-(defn run-queries
-  "Run the specified number of queries, return the results"
-  [queries]
-  (flatten (repeatedly queries get-world-random)))
-
 (defn get-query-count [queries]
   "Parse provided string value of query count, clamping values to between 1 and 500."
   (let [n (try (Integer/parseInt queries)
@@ -57,6 +52,11 @@
       (> n 500) 500
       :else n)))
 
+(defn run-queries
+  "Run the specified number of queries, return the results"
+  [queries]
+  (flatten (repeatedly (get-query-count queries) get-world-random)))
+
 (defn get-fortunes []
    "Fetch the full list of Fortunes from the database, sort them by the fortune
   message text, and then return the results."
@@ -69,7 +69,7 @@
   "Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   [queries]
-  (for [world (-> queries get-query-count run-queries)]
+  (for [world (-> queries run-queries)]
     (let [updated-world (assoc world :randomNumber (inc (rand-int 9999)))]
       (update-world<! updated-world {:connection @db})
       updated-world)))

+ 0 - 2
frameworks/Clojure/luminus/hello/src/hello/routes/home.clj

@@ -18,7 +18,6 @@
   "Test 3: Multiple database query"
   [queries]
   (-> queries
-      db/get-query-count
       db/run-queries
       response))
 
@@ -31,7 +30,6 @@
   "Test 5: Database updates"
   [queries]
   (-> queries
-      db/get-query-count
       db/update-and-persist
       response))