0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

Improve fixtures and media loader entry points.

This commit is contained in:
Andrey Antukh 2020-04-08 13:54:30 +02:00
parent a9b2951d8b
commit d737069ef9
4 changed files with 50 additions and 22 deletions

View file

@ -67,7 +67,7 @@
returning id;")
(def sql:create-icon-library
"insert into icon_library (team_id, name)
"insert into icon_library (team_id, name)
values ($1, $2)
returning id;")
@ -87,7 +87,7 @@
:num-draft-files-per-profile 10
:num-draft-pages-per-file 3})
(defn rng-ids
(defn- rng-ids
[rng n max]
(let [stream (->> (.longs rng 0 max)
(.iterator)
@ -99,19 +99,19 @@
#{}
stream)))
(defn rng-vec
(defn- rng-vec
[rng vdata n]
(let [ids (rng-ids rng n (count vdata))]
(mapv #(nth vdata %) ids)))
(defn rng-nth
(defn- rng-nth
[rng vdata]
(let [stream (->> (.longs rng 0 (count vdata))
(.iterator)
(iterator-seq))]
(nth vdata (first stream))))
(defn collect
(defn- collect
[f items]
(reduce (fn [acc n]
(p/then acc (fn [acc]
@ -121,7 +121,7 @@
(p/promise [])
items))
(defn run
(defn impl-run
[opts]
(let [rng (java.util.Random. 1)
@ -269,6 +269,17 @@
(assign-teams-and-profiles conn teams (map :id profiles))
(p/run! (partial create-draft-files conn) profiles)))))
(defn run
[preset]
(let [preset (if (map? preset)
preset
(case preset
(nil "small" :small) preset-small
;; "medium" preset-medium
;; "big" preset-big
preset-small))]
(deref (impl-run preset))))
(defn -main
[& args]
(try
@ -277,12 +288,7 @@
#'uxbox.db/pool
#'uxbox.migrations/migrations})
(mount/start))
(let [preset (case (first args)
(nil "small") preset-small
;; "medium" preset-medium
;; "big" preset-big
preset-small)]
(log/info "Using preset:" (pr-str preset))
(deref (run preset)))
(run (first args))
(finally
(mount/stop))))

View file

@ -310,8 +310,7 @@
(defn- read-file
[path]
(let [path (validate-path path)
reader (java.io.PushbackReader. (io/reader path))]
(let [reader (java.io.PushbackReader. (io/reader path))]
[(fs/parent path)
(read reader)]))
@ -335,11 +334,16 @@
(p/run! #(process-colors-library conn %) colors)
nil)))
(defn run
[path]
(p/let [[basedir data] (read-file path)]
(db/with-atomic [conn db/pool]
(importer conn basedir data))))
(defn -main
[& [path]]
(let [[basedir data] (read-file path)]
(let [path (validate-path path)]
(start-system)
(-> (db/with-atomic [conn db/pool]
(importer conn basedir data))
(p/finally (fn [_ _]
(stop-system))))))
(-> (run path)
(p/finally (fn [_ _] (stop-system))))))

View file

@ -10,9 +10,8 @@ This is a development feature that allows populate the database with a
good amount of random content (usually used for just test the
application or perform performance tweaks on queries).
In order to load fixtures, enter to the REPL environment executing the
`bin/repl` script, and then execute `(uxbox.fixtures/-main)`.
`bin/repl` script, and then execute `(uxbox.fixtures/run :small)`.
You also can execute this as a standalone script with:

View file

@ -36,6 +36,18 @@ respective defaults):
- `UXBOX_DEBUG_HUMANIZE_TRANSIT=true`
## REPL ##
The production environment by default starts a server REPL where you
can connect and perform diagnosis operations. For this you will need
`netcat` or `telnet` installed in the server.
```bash
$ rlwrap netcat localhost 5555
user=>
```
## Collections import ##
This is the way we can preload default collections of images and icons to the
@ -64,3 +76,10 @@ Then, you need to execute:
```bash
clojure -Adev -m uxbox.media-loader ../path/to/config.edn
```
If you have a REPL access to the running process, you can execute it from there:
```clojure
(require 'uxbox.media-loader)
@(uxbox.media-loader/run "/path/to/config.edn")
```