0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

🐛 Fix generating unnecessary thumbnails

This commit is contained in:
Aitor 2024-01-04 14:25:22 +01:00 committed by Alonso Torres
parent a76e5940af
commit b47cea7ead
3 changed files with 33 additions and 35 deletions

View file

@ -580,11 +580,11 @@
(ptk/reify ::detach-components (ptk/reify ::detach-components
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(let [undo-id (js/Symbol)] (let [undo-id (js/Symbol)]
(rx/concat (rx/concat
(rx/of (dwu/start-undo-transaction undo-id)) (rx/of (dwu/start-undo-transaction undo-id))
(rx/map #(detach-component %) (rx/from ids)) (rx/map #(detach-component %) (rx/from ids))
(rx/of (dwu/commit-undo-transaction undo-id))))))) (rx/of (dwu/commit-undo-transaction undo-id)))))))
(def detach-selected-components (def detach-selected-components
(ptk/reify ::detach-selected-components (ptk/reify ::detach-selected-components
@ -797,12 +797,12 @@
(watch [_ state _] (watch [_ state _]
(let [current-file-id (:current-file-id state) (let [current-file-id (:current-file-id state)
undo-id (js/Symbol)] undo-id (js/Symbol)]
(rx/of (rx/of
(dwu/start-undo-transaction undo-id) (dwu/start-undo-transaction undo-id)
(sync-file current-file-id file-id :components component-id undo-group) (sync-file current-file-id file-id :components component-id undo-group)
(when (not= current-file-id file-id) (when (not= current-file-id file-id)
(sync-file file-id file-id :components component-id undo-group)) (sync-file file-id file-id :components component-id undo-group))
(dwu/commit-undo-transaction undo-id))))))) (dwu/commit-undo-transaction undo-id)))))))
(defn update-component-thumbnail (defn update-component-thumbnail
"Update the thumbnail of the component with the given id, in the "Update the thumbnail of the component with the given id, in the
@ -811,12 +811,7 @@
(ptk/reify ::update-component-thumbnail (ptk/reify ::update-component-thumbnail
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(rx/of (update-component-thumbnail-sync state component-id file-id "component")) (rx/of (update-component-thumbnail-sync state component-id file-id "component")))))
#_(let [data (get state :workspace-data)
component (ctkl/get-component data component-id)
page-id (:main-instance-page component)
root-id (:main-instance-id component)]
(rx/of (dwt/request-thumbnail file-id page-id root-id "component"))))))
(defn- find-shape-index (defn- find-shape-index
[objects id shape-id] [objects id shape-id]
@ -965,15 +960,15 @@
find-frames (fn [change] find-frames (fn [change]
(->> (ch/frames-changed file change) (->> (ch/frames-changed file change)
(map #(assoc %1 :page-id (:page-id change))))) (map #(assoc %1 :page-id (:page-id change)))))
updated-frames (->> changes updated-frames (->> changes
:redo-changes :redo-changes
(mapcat find-frames) (mapcat find-frames)
distinct)] distinct)]
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes (log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
(:redo-changes changes) (:redo-changes changes)

View file

@ -10,7 +10,6 @@
[app.common.files.helpers :as cfh] [app.common.files.helpers :as cfh]
[app.common.logging :as l] [app.common.logging :as l]
[app.common.thumbnails :as thc] [app.common.thumbnails :as thc]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.notifications :as-alias wnt] [app.main.data.workspace.notifications :as-alias wnt]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
@ -183,7 +182,7 @@
(rx/filter (ptk/type? ::clear-thumbnail)) (rx/filter (ptk/type? ::clear-thumbnail))
(rx/filter #(= (deref %) object-id))))))))) (rx/filter #(= (deref %) object-id)))))))))
(defn- extract-frame-changes (defn- extract-root-frame-changes
"Process a changes set in a commit to extract the frames that are changing" "Process a changes set in a commit to extract the frames that are changing"
[page-id [event [old-data new-data]]] [page-id [event [old-data new-data]]]
(let [changes (-> event deref :changes) (let [changes (-> event deref :changes)
@ -209,10 +208,10 @@
new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))] new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))]
(cond-> #{} (cond-> #{}
(and (some? old-frame-id) (not= uuid/zero old-frame-id)) (cfh/root-frame? old-objects old-frame-id)
(conj old-frame-id) (conj old-frame-id)
(and (some? new-frame-id) (not= uuid/zero new-frame-id)) (cfh/root-frame? new-objects new-frame-id)
(conj new-frame-id))))] (conj new-frame-id))))]
(into #{} (into #{}
@ -251,16 +250,16 @@
(rx/filter dch/commit-changes?) (rx/filter dch/commit-changes?)
(rx/observe-on :async) (rx/observe-on :async)
(rx/with-latest-from workspace-data-s) (rx/with-latest-from workspace-data-s)
(rx/merge-map (partial extract-frame-changes page-id)) (rx/merge-map (partial extract-root-frame-changes page-id))
(rx/tap #(l/trc :hint "inconming change" :origin "local" :frame-id (dm/str %)))) (rx/tap #(l/trc :hint "incoming change" :origin "local" :frame-id (dm/str %))))
;; NOTIFICATIONS CHANGES ;; NOTIFICATIONS CHANGES
(->> stream (->> stream
(rx/filter (ptk/type? ::wnt/handle-file-change)) (rx/filter (ptk/type? ::wnt/handle-file-change))
(rx/observe-on :async) (rx/observe-on :async)
(rx/with-latest-from workspace-data-s) (rx/with-latest-from workspace-data-s)
(rx/merge-map (partial extract-frame-changes page-id)) (rx/merge-map (partial extract-root-frame-changes page-id))
(rx/tap #(l/trc :hint "inconming change" :origin "notifications" :frame-id (dm/str %)))) (rx/tap #(l/trc :hint "incoming change" :origin "notifications" :frame-id (dm/str %))))
;; PERSISTENCE CHANGES ;; PERSISTENCE CHANGES
(->> stream (->> stream
@ -270,7 +269,7 @@
(and (= file-id file-id) (and (= file-id file-id)
(= page-id page-id)))) (= page-id page-id))))
(rx/map (fn [[_ _ frame-id]] frame-id)) (rx/map (fn [[_ _ frame-id]] frame-id))
(rx/tap #(l/trc :hint "inconming change" :origin "persistence" :frame-id (dm/str %))))) (rx/tap #(l/trc :hint "incoming change" :origin "persistence" :frame-id (dm/str %)))))
(rx/share)) (rx/share))
@ -285,15 +284,13 @@
;; and interrupt any ongoing update-thumbnail process ;; and interrupt any ongoing update-thumbnail process
;; related to current frame-id ;; related to current frame-id
(->> changes-s (->> changes-s
(rx/map (fn [frame-id] (rx/map #(clear-thumbnail file-id page-id % "frame")))
(clear-thumbnail file-id page-id frame-id "frame"))))
;; Generate thumbnails in batchs, once user becomes ;; Generate thumbnails in batchs, once user becomes
;; inactive for some instant ;; inactive for some instant
(->> changes-s (->> changes-s
(rx/buffer-until notifier-s) (rx/buffer-until notifier-s)
(rx/mapcat #(into #{} %)) (rx/mapcat #(into #{} %))
(rx/map (fn [frame-id] (rx/map #(request-thumbnail file-id page-id % "frame"))))
(request-thumbnail file-id page-id frame-id "frame")))))
(rx/take-until stopper-s)))))) (rx/take-until stopper-s))))))

View file

@ -243,6 +243,12 @@
(prn (str (:name frame) " - " (:id frame)))) (prn (str (:name frame) " - " (:id frame))))
nil)) nil))
(defn ^:export select-by-object-id
[object-id]
(let [[_ page-id shape-id _] (str/split object-id #"/")]
(st/emit! (dw/go-to-page (uuid/uuid page-id)))
(st/emit! (dws/select-shape (uuid/uuid shape-id)))))
(defn ^:export select-by-id (defn ^:export select-by-id
[shape-id] [shape-id]
(st/emit! (dws/select-shape (uuid/uuid shape-id)))) (st/emit! (dws/select-shape (uuid/uuid shape-id))))