mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 14:46:12 +02:00
⚡ Improve performance and resolve render issues on exporter.
This commit is contained in:
parent
fd3f304e07
commit
d1e4f0de3e
5 changed files with 71 additions and 23 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
(ns app.rpc.queries.files
|
(ns app.rpc.queries.files
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.migrations :as pmg]
|
[app.common.pages.migrations :as pmg]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
@ -215,6 +217,42 @@
|
||||||
(some-> (retrieve-file cfg id)
|
(some-> (retrieve-file cfg id)
|
||||||
(assoc :permissions perms)))))
|
(assoc :permissions perms)))))
|
||||||
|
|
||||||
|
(declare trim-file-data)
|
||||||
|
|
||||||
|
(s/def ::page-id ::us/uuid)
|
||||||
|
(s/def ::object-id ::us/uuid)
|
||||||
|
|
||||||
|
(s/def ::trimmed-file
|
||||||
|
(s/keys :req-un [::profile-id ::id ::object-id ::page-id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::trimmed-file
|
||||||
|
"Retrieve a file by its ID and trims all unnecesary content from
|
||||||
|
it. It is mainly used for rendering a concrete object, so we don't
|
||||||
|
need force download all shapes when only a small subset is
|
||||||
|
necesseary."
|
||||||
|
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
||||||
|
(db/with-atomic [conn pool]
|
||||||
|
(let [cfg (assoc cfg :conn conn)
|
||||||
|
perms (get-permissions conn profile-id id)]
|
||||||
|
(check-read-permissions! perms)
|
||||||
|
(some-> (retrieve-file cfg id)
|
||||||
|
(trim-file-data params)
|
||||||
|
(assoc :permissions perms)))))
|
||||||
|
|
||||||
|
(defn- trim-file-data
|
||||||
|
[file {:keys [page-id object-id]}]
|
||||||
|
(let [page (get-in file [:data :pages-index page-id])
|
||||||
|
objects (->> (:objects page)
|
||||||
|
(cp/get-object-with-children object-id)
|
||||||
|
(map #(dissoc % :thumbnail)))
|
||||||
|
|
||||||
|
objects (d/index-by :id objects)
|
||||||
|
page (assoc page :objects objects)]
|
||||||
|
|
||||||
|
(-> file
|
||||||
|
(update :data assoc :pages-index {page-id page})
|
||||||
|
(assoc :pages [page-id]))))
|
||||||
|
|
||||||
(defn remove-thumbnails-frames
|
(defn remove-thumbnails-frames
|
||||||
"Removes from data the children for frames that have a thumbnail set up"
|
"Removes from data the children for frames that have a thumbnail set up"
|
||||||
[data]
|
[data]
|
||||||
|
|
|
@ -67,25 +67,21 @@
|
||||||
type "png"
|
type "png"
|
||||||
omit-background? false}}]
|
omit-background? false}}]
|
||||||
(.screenshot ^js frame #js {:fullPage full-page?
|
(.screenshot ^js frame #js {:fullPage full-page?
|
||||||
|
:clip nil
|
||||||
:type (name type)
|
:type (name type)
|
||||||
:omitBackground omit-background?})))
|
:omitBackground omit-background?})))
|
||||||
|
|
||||||
(defn pdf
|
(defn pdf
|
||||||
([page] (pdf page nil))
|
([page] (pdf page nil))
|
||||||
([page {:keys [viewport omit-background? prefer-css-page-size? save-path]
|
([page {:keys [viewport save-path]}]
|
||||||
:or {viewport {}
|
(p/let [viewport (d/merge default-viewport viewport)]
|
||||||
omit-background? true
|
(.emulateMediaType ^js page "screen")
|
||||||
prefer-css-page-size? true
|
|
||||||
save-path nil}}]
|
|
||||||
(let [viewport (d/merge default-viewport viewport)]
|
|
||||||
(.pdf ^js page #js {:path save-path
|
(.pdf ^js page #js {:path save-path
|
||||||
:width (:width viewport)
|
:width (:width viewport)
|
||||||
:height (:height viewport)
|
:height (:height viewport)
|
||||||
:scale (:scale viewport)
|
:scale (:scale viewport)
|
||||||
:omitBackground omit-background?
|
:printBackground true
|
||||||
:printBackground (not omit-background?)
|
:preferCSSPageSize false}))))
|
||||||
:preferCSSPageSize prefer-css-page-size?}))))
|
|
||||||
|
|
||||||
(defn eval!
|
(defn eval!
|
||||||
[frame f]
|
[frame f]
|
||||||
(.evaluate ^js frame f))
|
(.evaluate ^js frame f))
|
||||||
|
|
|
@ -31,20 +31,26 @@
|
||||||
(let [path (str "/render-object/" file-id "/" page-id "/" object-id)
|
(let [path (str "/render-object/" file-id "/" page-id "/" object-id)
|
||||||
uri (-> (u/uri (cf/get :public-uri))
|
uri (-> (u/uri (cf/get :public-uri))
|
||||||
(assoc :path "/")
|
(assoc :path "/")
|
||||||
|
(assoc :query "essential=t")
|
||||||
(assoc :fragment path))
|
(assoc :fragment path))
|
||||||
|
|
||||||
cookie (create-cookie uri token)]
|
cookie (create-cookie uri token)]
|
||||||
(pdf-from page (str uri) cookie)))
|
(pdf-from page (str uri) cookie)))
|
||||||
|
|
||||||
(pdf-from [page uri cookie]
|
(pdf-from [page uri cookie]
|
||||||
(l/info :uri uri)
|
(l/info :uri uri)
|
||||||
(let [options {:cookie cookie}]
|
(p/let [options {:cookie cookie}]
|
||||||
(p/do!
|
|
||||||
(bw/configure-page! page options)
|
(bw/configure-page! page options)
|
||||||
(bw/navigate! page uri)
|
(bw/navigate! page uri)
|
||||||
(bw/wait-for page "#screenshot")
|
(bw/wait-for page "#screenshot")
|
||||||
|
;; taking png screenshot before pdf, helps to make the
|
||||||
|
;; pdf rendering works as expected.
|
||||||
|
(p/let [dom (bw/select page "#screenshot")]
|
||||||
|
(bw/screenshot dom {:full-page? true}))
|
||||||
|
|
||||||
(if save-path
|
(if save-path
|
||||||
(bw/pdf page {:save-path save-path})
|
(bw/pdf page {:save-path save-path})
|
||||||
(bw/pdf page)))))]
|
(bw/pdf page))))]
|
||||||
|
|
||||||
(bw/exec! handle)))
|
(bw/exec! handle)))
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
[app.main.ui.routes :as rt]
|
[app.main.ui.routes :as rt]
|
||||||
[app.main.worker :as worker]
|
[app.main.worker :as worker]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
[app.util.globals :as glob]
|
||||||
[app.util.i18n :as i18n]
|
[app.util.i18n :as i18n]
|
||||||
[app.util.theme :as theme]
|
[app.util.theme :as theme]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[debug]
|
[debug]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
@ -58,12 +60,18 @@
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
(rx/map #(rt/init-routes)))))))
|
(rx/map #(rt/init-routes)))))))
|
||||||
|
|
||||||
|
(def essential-only?
|
||||||
|
(let [href (.-href ^js glob/location)]
|
||||||
|
(str/includes? href "essential=t")))
|
||||||
|
|
||||||
(defn ^:export init
|
(defn ^:export init
|
||||||
[]
|
[]
|
||||||
|
(when-not essential-only?
|
||||||
(worker/init!)
|
(worker/init!)
|
||||||
(sentry/init!)
|
(sentry/init!)
|
||||||
(i18n/init! cf/translations)
|
(i18n/init! cf/translations)
|
||||||
(theme/init! cf/themes)
|
(theme/init! cf/themes))
|
||||||
|
|
||||||
(init-ui)
|
(init-ui)
|
||||||
(st/emit! (initialize)))
|
(st/emit! (initialize)))
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
(fn []
|
(fn []
|
||||||
(->> (rx/zip
|
(->> (rx/zip
|
||||||
(repo/query! :font-variants {:file-id file-id})
|
(repo/query! :font-variants {:file-id file-id})
|
||||||
(repo/query! :file {:id file-id}))
|
(repo/query! :trimmed-file {:id file-id :page-id page-id :object-id object-id}))
|
||||||
(rx/subs
|
(rx/subs
|
||||||
(fn [[fonts {:keys [data]}]]
|
(fn [[fonts {:keys [data]}]]
|
||||||
(when (seq fonts)
|
(when (seq fonts)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue