mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Run path-conflicting just once for quarantine router
This commit is contained in:
parent
0d3a195cd8
commit
b128a0f3db
2 changed files with 17 additions and 4 deletions
|
|
@ -301,7 +301,7 @@
|
|||
([compiled-routes]
|
||||
(quarantine-router compiled-routes {}))
|
||||
([compiled-routes opts]
|
||||
(let [conflicting-paths (-> compiled-routes (impl/path-conflicting-routes opts) impl/conflicting-paths)
|
||||
(let [conflicting-paths (impl/conflicting-paths (or (::path-conflicting opts) (impl/path-conflicting-routes compiled-routes opts)))
|
||||
conflicting? #(contains? conflicting-paths (first %))
|
||||
{conflicting true, non-conflicting false} (group-by conflicting? compiled-routes)
|
||||
linear-router (linear-router conflicting opts)
|
||||
|
|
@ -389,7 +389,7 @@
|
|||
(when-let [validate (:validate opts)]
|
||||
(validate compiled-routes opts))
|
||||
|
||||
(router compiled-routes opts))
|
||||
(router compiled-routes (assoc opts ::path-conflicting path-conflicting)))
|
||||
|
||||
(catch #?(:clj Exception, :cljs js/Error) e
|
||||
(throw ((get opts :exception identity) e)))))))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(ns reitit.router-creation-perf-test
|
||||
(:require [reitit.perf-utils :refer [bench!]]
|
||||
(:require [reitit.perf-utils :refer [bench! suite]]
|
||||
[reitit.core :as r]
|
||||
[clojure.string :as str])
|
||||
(:import (java.util Random)))
|
||||
|
|
@ -32,12 +32,25 @@
|
|||
(let [rnd (random 1)]
|
||||
(mapv (fn [n] [(route rnd) (keyword (str "route" n))]) (range 100))))
|
||||
|
||||
(conj hundred-routes (last hundred-routes))
|
||||
|
||||
|
||||
(defn bench-routers []
|
||||
|
||||
(suite "non-conflicting")
|
||||
|
||||
;; 104ms
|
||||
(bench! "default" (r/router hundred-routes))
|
||||
|
||||
;; 7ms
|
||||
(bench! "linear" (r/router hundred-routes {:router r/linear-router, :conflicts nil})))
|
||||
(bench! "linear" (r/router hundred-routes {:router r/linear-router, :conflicts nil}))
|
||||
|
||||
(suite "conflicting")
|
||||
(let [routes (conj hundred-routes [(first (last hundred-routes)) ::route])]
|
||||
|
||||
;; 205ms
|
||||
;; 105ms (cache path-conflicts)
|
||||
(bench! "default" (r/router routes {:conflicts nil}))))
|
||||
|
||||
(comment
|
||||
(bench-routers))
|
||||
|
|
|
|||
Loading…
Reference in a new issue