Improve performance and resolve render issues on exporter.

This commit is contained in:
Andrey Antukh 2022-01-18 16:58:00 +01:00 committed by Andrés Moya
parent fd3f304e07
commit d1e4f0de3e
5 changed files with 71 additions and 23 deletions

View file

@ -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]