mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
✨ Make retrieving fdata for thumbnail to no modify the file
This prevents that file to be considered opened just for creating the thumbnail for it.
This commit is contained in:
parent
ac20451ae7
commit
0ad2e8a0f2
1 changed files with 30 additions and 39 deletions
|
@ -10,6 +10,7 @@
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
|
[app.common.files.migrations :as fmg]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.thumbnails :as thc]
|
[app.common.thumbnails :as thc]
|
||||||
|
@ -105,24 +106,12 @@
|
||||||
(letfn [;; function responsible on finding the frame marked to be
|
(letfn [;; function responsible on finding the frame marked to be
|
||||||
;; used as thumbnail; the returned frame always have
|
;; used as thumbnail; the returned frame always have
|
||||||
;; the :page-id set to the page that it belongs.
|
;; the :page-id set to the page that it belongs.
|
||||||
|
(get-thumbnail-frame [{:keys [data]}]
|
||||||
(get-thumbnail-frame [file]
|
(d/seek #(or (:use-for-thumbnail %)
|
||||||
;; NOTE: this is a hack for avoid perform blocking
|
(:use-for-thumbnail? %)) ; NOTE: backward comp (remove on v1.21)
|
||||||
;; operation inside the for loop, clojure lazy-seq uses
|
(for [page (-> data :pages-index vals)
|
||||||
;; synchronized blocks that does not plays well with
|
frame (-> page :objects ctt/get-frames)]
|
||||||
;; virtual threads where all rpc methods calls are
|
(assoc frame :page-id (:id page)))))
|
||||||
;; dispatched, so we need to perform the load operation
|
|
||||||
;; first. This operation forces all pointer maps load into
|
|
||||||
;; the memory.
|
|
||||||
;;
|
|
||||||
;; FIXME: this is no longer true with clojure>=1.12
|
|
||||||
(let [{:keys [data]} (update file :data feat.fdata/process-pointers pmap/load!)]
|
|
||||||
;; Then proceed to find the frame set for thumbnail
|
|
||||||
(d/seek #(or (:use-for-thumbnail %)
|
|
||||||
(:use-for-thumbnail? %)) ; NOTE: backward comp (remove on v1.21)
|
|
||||||
(for [page (-> data :pages-index vals)
|
|
||||||
frame (-> page :objects ctt/get-frames)]
|
|
||||||
(assoc frame :page-id (:id page))))))
|
|
||||||
|
|
||||||
;; function responsible to filter objects data structure of
|
;; function responsible to filter objects data structure of
|
||||||
;; all unneeded shapes if a concrete frame is provided. If no
|
;; all unneeded shapes if a concrete frame is provided. If no
|
||||||
|
@ -166,30 +155,29 @@
|
||||||
|
|
||||||
objects)))]
|
objects)))]
|
||||||
|
|
||||||
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)]
|
(let [frame (get-thumbnail-frame file)
|
||||||
(let [frame (get-thumbnail-frame file)
|
frame-id (:id frame)
|
||||||
frame-id (:id frame)
|
page-id (or (:page-id frame)
|
||||||
page-id (or (:page-id frame)
|
(-> data :pages first))
|
||||||
(-> data :pages first))
|
|
||||||
|
|
||||||
page (dm/get-in data [:pages-index page-id])
|
page (dm/get-in data [:pages-index page-id])
|
||||||
page (cond-> page (pmap/pointer-map? page) deref)
|
page (cond-> page (pmap/pointer-map? page) deref)
|
||||||
frame-ids (if (some? frame) (list frame-id) (map :id (ctt/get-frames (:objects page))))
|
frame-ids (if (some? frame) (list frame-id) (map :id (ctt/get-frames (:objects page))))
|
||||||
|
|
||||||
obj-ids (map #(thc/fmt-object-id (:id file) page-id % "frame") frame-ids)
|
obj-ids (map #(thc/fmt-object-id (:id file) page-id % "frame") frame-ids)
|
||||||
thumbs (get-object-thumbnails conn id obj-ids)]
|
thumbs (get-object-thumbnails conn id obj-ids)]
|
||||||
|
|
||||||
(cond-> page
|
(cond-> page
|
||||||
;; If we have frame, we need to specify it on the page level
|
;; If we have frame, we need to specify it on the page level
|
||||||
;; and remove the all other unrelated objects.
|
;; and remove the all other unrelated objects.
|
||||||
(some? frame-id)
|
(some? frame-id)
|
||||||
(-> (assoc :thumbnail-frame-id frame-id)
|
(-> (assoc :thumbnail-frame-id frame-id)
|
||||||
(update :objects filter-objects frame-id))
|
(update :objects filter-objects frame-id))
|
||||||
|
|
||||||
;; Assoc the available thumbnails and prune not visible shapes
|
;; Assoc the available thumbnails and prune not visible shapes
|
||||||
;; for avoid transfer unnecessary data.
|
;; for avoid transfer unnecessary data.
|
||||||
:always
|
:always
|
||||||
(update :objects assoc-thumbnails page-id thumbs))))))
|
(update :objects assoc-thumbnails page-id thumbs)))))
|
||||||
|
|
||||||
(def ^:private
|
(def ^:private
|
||||||
schema:get-file-data-for-thumbnail
|
schema:get-file-data-for-thumbnail
|
||||||
|
@ -221,7 +209,10 @@
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:file-id file-id)
|
:file-id file-id)
|
||||||
|
|
||||||
file (files/get-file cfg file-id)]
|
file (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
|
||||||
|
(-> (files/get-file cfg file-id :migrate? false)
|
||||||
|
(update :data feat.fdata/process-pointers deref)
|
||||||
|
(fmg/migrate-file)))]
|
||||||
|
|
||||||
(-> (cfeat/get-team-enabled-features cf/flags team)
|
(-> (cfeat/get-team-enabled-features cf/flags team)
|
||||||
(cfeat/check-client-features! (:features params))
|
(cfeat/check-client-features! (:features params))
|
||||||
|
|
Loading…
Add table
Reference in a new issue