Skip to content

Instantly share code, notes, and snippets.

@escherize
Created January 17, 2024 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save escherize/780e5141a84db7ee4110b1ed534b2bd1 to your computer and use it in GitHub Desktop.
Save escherize/780e5141a84db7ee4110b1ed534b2bd1 to your computer and use it in GitHub Desktop.
(ns dev.nocommit.massive-perm-graph
(:require [metabase.test :as mt]
[criterium.core :as criterium]
[metabase.util :as u]))
(comment
(defn get-graph [] (mt/user-http-request :crowberto :get 200 "permissions/graph"))
(defn inflate-permission-graph! []
(let [{:keys [groups revision]} (get-graph)
group-ids (-> groups keys)
db-ids (->> groups vals (mapcat keys))
the-permission {:data {:schemas "all", :native "write"}}
all-db-perms (zipmap db-ids (repeat the-permission))
the-group-ids (take 10 (shuffle group-ids))
groups (zipmap the-group-ids (repeat all-db-perms))]
(mt/user-http-request :crowberto :put 200 "permissions/graph"
{:groups groups :revision revision})
the-group-ids))
(dotimes [n 100]
(println "inflating..." n)
(inflate-permission-graph!))
(def groups {})
(def g (get-graph))
(def groups (let [group-ids (-> g :groups vals)
db-ids (->> g :groups vals (mapcat keys))
the-permission {:data {:schemas "all", :native "write"}}
all-db-perms (zipmap db-ids (repeat the-permission))]
(zipmap (filter #(-> % first key even?) group-ids) (repeat all-db-perms))))
(mt/user-http-request :crowberto :put 200 "permissions/graph"
{:groups groups :revision (:revision (get-graph))}))
(defn run-bench! [description thunk]
(spit "results.txt"
(str "\n----start----\n| "
description
"\n-------------\n"
(with-out-str (thunk))
"\n----end------\n")
:append true))
;; (run-bench! "1+1" (fn [] (criterium/quick-bench (+ 1 1))))
;; (def wut (mt/user-http-request :crowberto :get 200 "permissions/graph"))
;; (:groups wut)
(comment
(set! *warn-on-reflection* true)
(criterium/bench (+ 1 2))
(time (mt/user-http-request :crowberto :get 200 "permissions/graph"))
;; time: 26294.80275 msecs
(time (mt/user-http-request :crowberto :get 200 "permissions/graph/db/8"))
;;time: 139.985667 msecs
;; ~192 times faster
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment