Last active
July 4, 2024 04:48
-
-
Save qnkhuat/b04017b9e937d048b2ba5e615c860652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns stress-big-dashboard | |
(:require | |
[clojure.java.shell :as sh] | |
[metabase.test :as mt] | |
[toucan2.core :as t2] | |
[toucan2.tools.with-temp :as t2.with-temp])) | |
(defn create-cards | |
[n] | |
(let [tables (t2/select :model/Table :db_id (mt/id)) | |
get-table (fn [i] (nth tables (mod i (count tables))))] | |
(t2/insert-returning-instances! :model/Card (for [i (range n) | |
:let [table (get-table i)]] | |
(merge | |
(t2.with-temp/with-temp-defaults :model/Card) | |
{:table_id (:id table) | |
:name (format "Card %d with table %s" i (:name table)) | |
:dataset_query {:database (:db_id table) | |
:type :query | |
:query {:source-table (:id table)}}}))))) | |
(defn create-dashboard-cards | |
[dashboard-id cards] | |
(t2/insert! :model/DashboardCard (for [card cards] | |
(merge | |
(t2.with-temp/with-temp-defaults :model/DashboardCard) | |
{:dashboard_id dashboard-id | |
:card_id (:id card)})))) | |
(defn make-big-dashboard | |
[n-dashcards] | |
(let [dashboard-id (t2/insert-returning-pk! :model/Dashboard (t2.with-temp/with-temp-defaults :model/Dashboard))] | |
(create-dashboard-cards dashboard-id (create-cards n-dashcards)) | |
dashboard-id)) | |
(defn make-big-dashboard-complicated-card | |
[n-dashcards] | |
(let [card (t2/insert-returning-instance! :model/Card | |
(merge | |
(t2.with-temp/with-temp-defaults :model/Card) | |
{:database_id (mt/id) | |
:dataset_query (mt/mbql-query orders | |
{:filter [:> $orders.product_id 1] | |
:breakout [!month.orders.created_at] | |
:aggregation [:sum $orders.total] | |
:joins [{:fields "all", | |
:source-table (mt/id :products) | |
:condition [:= $orders.product_id &product.products.id] | |
:alias "product"}]})})) | |
dashboard-id (t2/insert-returning-pk! :model/Dashboard (t2.with-temp/with-temp-defaults :model/Dashboard))] | |
(create-dashboard-cards dashboard-id (repeatedly n-dashcards (constantly card))) | |
dashboard-id)) | |
#_(let [dashboard-id (make-big-dashboard 50) | |
tabs 10] | |
(doseq [_ (range tabs)] | |
(sh/sh "open" (str "http://localhost:3000/dashboard/" dashboard-id)))) | |
#_(let [dashboard-id (make-big-dashboard-complicated-card 50) | |
tabs 10] | |
(doseq [_ (range tabs)] | |
(sh/sh "open" (str "http://localhost:3000/dashboard/" dashboard-id)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment