mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 18:18:24 -05: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
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.migrations :as pmg]
|
||||
[app.common.spec :as us]
|
||||
[app.common.uuid :as uuid]
|
||||
|
@ -215,6 +217,42 @@
|
|||
(some-> (retrieve-file cfg id)
|
||||
(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
|
||||
"Removes from data the children for frames that have a thumbnail set up"
|
||||
[data]
|
||||
|
|
|
@ -67,25 +67,21 @@
|
|||
type "png"
|
||||
omit-background? false}}]
|
||||
(.screenshot ^js frame #js {:fullPage full-page?
|
||||
:clip nil
|
||||
:type (name type)
|
||||
:omitBackground omit-background?})))
|
||||
|
||||
(defn pdf
|
||||
([page] (pdf page nil))
|
||||
([page {:keys [viewport omit-background? prefer-css-page-size? save-path]
|
||||
:or {viewport {}
|
||||
omit-background? true
|
||||
prefer-css-page-size? true
|
||||
save-path nil}}]
|
||||
(let [viewport (d/merge default-viewport viewport)]
|
||||
([page {:keys [viewport save-path]}]
|
||||
(p/let [viewport (d/merge default-viewport viewport)]
|
||||
(.emulateMediaType ^js page "screen")
|
||||
(.pdf ^js page #js {:path save-path
|
||||
:width (:width viewport)
|
||||
:height (:height viewport)
|
||||
:scale (:scale viewport)
|
||||
:omitBackground omit-background?
|
||||
:printBackground (not omit-background?)
|
||||
:preferCSSPageSize prefer-css-page-size?}))))
|
||||
|
||||
:printBackground true
|
||||
:preferCSSPageSize false}))))
|
||||
(defn eval!
|
||||
[frame f]
|
||||
(.evaluate ^js frame f))
|
||||
|
|
|
@ -31,20 +31,26 @@
|
|||
(let [path (str "/render-object/" file-id "/" page-id "/" object-id)
|
||||
uri (-> (u/uri (cf/get :public-uri))
|
||||
(assoc :path "/")
|
||||
(assoc :query "essential=t")
|
||||
(assoc :fragment path))
|
||||
|
||||
cookie (create-cookie uri token)]
|
||||
(pdf-from page (str uri) cookie)))
|
||||
|
||||
(pdf-from [page uri cookie]
|
||||
(l/info :uri uri)
|
||||
(let [options {:cookie cookie}]
|
||||
(p/do!
|
||||
(bw/configure-page! page options)
|
||||
(bw/navigate! page uri)
|
||||
(bw/wait-for page "#screenshot")
|
||||
(if save-path
|
||||
(bw/pdf page {:save-path save-path})
|
||||
(bw/pdf page)))))]
|
||||
(p/let [options {:cookie cookie}]
|
||||
(bw/configure-page! page options)
|
||||
(bw/navigate! page uri)
|
||||
(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
|
||||
(bw/pdf page {:save-path save-path})
|
||||
(bw/pdf page))))]
|
||||
|
||||
(bw/exec! handle)))
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
[app.main.ui.routes :as rt]
|
||||
[app.main.worker :as worker]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as glob]
|
||||
[app.util.i18n :as i18n]
|
||||
[app.util.theme :as theme]
|
||||
[beicon.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[debug]
|
||||
[potok.core :as ptk]
|
||||
[rumext.alpha :as mf]))
|
||||
|
@ -58,12 +60,18 @@
|
|||
(rx/take 1)
|
||||
(rx/map #(rt/init-routes)))))))
|
||||
|
||||
(def essential-only?
|
||||
(let [href (.-href ^js glob/location)]
|
||||
(str/includes? href "essential=t")))
|
||||
|
||||
(defn ^:export init
|
||||
[]
|
||||
(worker/init!)
|
||||
(sentry/init!)
|
||||
(i18n/init! cf/translations)
|
||||
(theme/init! cf/themes)
|
||||
(when-not essential-only?
|
||||
(worker/init!)
|
||||
(sentry/init!)
|
||||
(i18n/init! cf/translations)
|
||||
(theme/init! cf/themes))
|
||||
|
||||
(init-ui)
|
||||
(st/emit! (initialize)))
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
(fn []
|
||||
(->> (rx/zip
|
||||
(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
|
||||
(fn [[fonts {:keys [data]}]]
|
||||
(when (seq fonts)
|
||||
|
|
Loading…
Add table
Reference in a new issue