Browse Source

chore: merge function util/with-time and util/with-time-number

Junyi Du 2 years ago
parent
commit
5ee8707469

+ 1 - 1
src/main/frontend/db/react.cljs

@@ -111,7 +111,7 @@
 
 
 (defn add-q!
 (defn add-q!
   [k query time inputs result-atom transform-fn query-fn inputs-fn]
   [k query time inputs result-atom transform-fn query-fn inputs-fn]
-  (let [time' (int (util/safe-parse-float time))]
+  (let [time' (int (util/safe-parse-float time))] ;; for robustness. `time` should already be float
     (swap! query-state assoc k {:query query
     (swap! query-state assoc k {:query query
                                :query-time time'
                                :query-time time'
                                :inputs inputs
                                :inputs inputs

+ 1 - 11
src/main/frontend/util.cljc

@@ -1041,17 +1041,7 @@
 #?(:clj
 #?(:clj
    (defmacro with-time
    (defmacro with-time
      "Evaluates expr and prints the time it took. 
      "Evaluates expr and prints the time it took. 
-      Returns the value of expr and the spent time of string in msecs."
-     [expr]
-     `(let [start# (cljs.core/system-time)
-            ret# ~expr]
-        {:result ret#
-         :time (.toFixed (- (cljs.core/system-time) start#) 6)})))
-
-#?(:clj
-   (defmacro with-time-number
-     "Evaluates expr and prints the time it took. 
-      Returns the value of expr and the spent time of number in msecs."
+      Returns the value of expr and the spent time of float number in msecs."
      [expr]
      [expr]
      `(let [start# (cljs.core/system-time)
      `(let [start# (cljs.core/system-time)
             ret# ~expr]
             ret# ~expr]

+ 1 - 1
src/test/frontend/components/query_table_test.cljs

@@ -72,7 +72,7 @@
 
 
   (testing "monitor time of sort by integer block property"
   (testing "monitor time of sort by integer block property"
     (are [sort-state result _sorted-result timeout]
     (are [sort-state result _sorted-result timeout]
-         (>= timeout (:time (util/with-time-number (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))))
+         (>= timeout (:time (util/with-time (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))))
       {:sort-desc? true :sort-by-column :rating}
       {:sort-desc? true :sort-by-column :rating}
       [{:rating 8} {:rating 7}]
       [{:rating 8} {:rating 7}]
       [{:rating 8} {:rating 7}]
       [{:rating 8} {:rating 7}]

+ 2 - 2
src/test/frontend/format/block_test.cljs

@@ -21,7 +21,7 @@
 
 
 (deftest monitor-normalize-date-time
 (deftest monitor-normalize-date-time
   (testing "monitor time consumption of normalize date values"
   (testing "monitor time consumption of normalize date values"
-    (are [x _y timeout] (>= timeout (:time (util/with-time-number (block/normalize-block x true))))
+    (are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x true))))
       "Aug 12th, 2022"
       "Aug 12th, 2022"
       "2022-08-12T00:00:00Z"
       "2022-08-12T00:00:00Z"
       50.0 ;; actual 2.2
       50.0 ;; actual 2.2
@@ -74,7 +74,7 @@
 
 
 (deftest monitor-normalize-randome-values-time
 (deftest monitor-normalize-randome-values-time
   (testing "monitor time consumption of random values should not be processed"
   (testing "monitor time consumption of random values should not be processed"
-    (are [x _y timeout] (>= timeout (:time (util/with-time-number (block/normalize-block x false))))
+    (are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x false))))
       "anreanre"
       "anreanre"
       "anreanre"
       "anreanre"
       2.0 ;; actual 0.07
       2.0 ;; actual 0.07