From b47cea7ead30e630962ad042cefc9aa21066d0bf Mon Sep 17 00:00:00 2001 From: Aitor Date: Thu, 4 Jan 2024 14:25:22 +0100 Subject: [PATCH] :bug: Fix generating unnecessary thumbnails --- .../app/main/data/workspace/libraries.cljs | 39 ++++++++----------- .../app/main/data/workspace/thumbnails.cljs | 23 +++++------ frontend/src/debug.cljs | 6 +++ 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 99a078fbb..601322d27 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -580,11 +580,11 @@ (ptk/reify ::detach-components ptk/WatchEvent (watch [_ _ _] - (let [undo-id (js/Symbol)] - (rx/concat - (rx/of (dwu/start-undo-transaction undo-id)) - (rx/map #(detach-component %) (rx/from ids)) - (rx/of (dwu/commit-undo-transaction undo-id))))))) + (let [undo-id (js/Symbol)] + (rx/concat + (rx/of (dwu/start-undo-transaction undo-id)) + (rx/map #(detach-component %) (rx/from ids)) + (rx/of (dwu/commit-undo-transaction undo-id))))))) (def detach-selected-components (ptk/reify ::detach-selected-components @@ -797,12 +797,12 @@ (watch [_ state _] (let [current-file-id (:current-file-id state) undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (sync-file current-file-id file-id :components component-id undo-group) - (when (not= current-file-id file-id) - (sync-file file-id file-id :components component-id undo-group)) - (dwu/commit-undo-transaction undo-id))))))) + (rx/of + (dwu/start-undo-transaction undo-id) + (sync-file current-file-id file-id :components component-id undo-group) + (when (not= current-file-id file-id) + (sync-file file-id file-id :components component-id undo-group)) + (dwu/commit-undo-transaction undo-id))))))) (defn update-component-thumbnail "Update the thumbnail of the component with the given id, in the @@ -811,12 +811,7 @@ (ptk/reify ::update-component-thumbnail ptk/WatchEvent (watch [_ state _] - (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")))))) + (rx/of (update-component-thumbnail-sync state component-id file-id "component"))))) (defn- find-shape-index [objects id shape-id] @@ -965,15 +960,15 @@ find-frames (fn [change] - (->> (ch/frames-changed file change) - (map #(assoc %1 :page-id (:page-id change))))) + (->> (ch/frames-changed file change) + (map #(assoc %1 :page-id (:page-id change))))) updated-frames (->> changes - :redo-changes - (mapcat find-frames) - distinct)] + :redo-changes + (mapcat find-frames) + distinct)] (log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes (:redo-changes changes) diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index 577054231..6582a01c8 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -10,7 +10,6 @@ [app.common.files.helpers :as cfh] [app.common.logging :as l] [app.common.thumbnails :as thc] - [app.common.uuid :as uuid] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.notifications :as-alias wnt] [app.main.data.workspace.state-helpers :as wsh] @@ -183,7 +182,7 @@ (rx/filter (ptk/type? ::clear-thumbnail)) (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" [page-id [event [old-data new-data]]] (let [changes (-> event deref :changes) @@ -209,10 +208,10 @@ new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))] (cond-> #{} - (and (some? old-frame-id) (not= uuid/zero old-frame-id)) + (cfh/root-frame? old-objects 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))))] (into #{} @@ -251,16 +250,16 @@ (rx/filter dch/commit-changes?) (rx/observe-on :async) (rx/with-latest-from workspace-data-s) - (rx/merge-map (partial extract-frame-changes page-id)) - (rx/tap #(l/trc :hint "inconming change" :origin "local" :frame-id (dm/str %)))) + (rx/merge-map (partial extract-root-frame-changes page-id)) + (rx/tap #(l/trc :hint "incoming change" :origin "local" :frame-id (dm/str %)))) ;; NOTIFICATIONS CHANGES (->> stream (rx/filter (ptk/type? ::wnt/handle-file-change)) (rx/observe-on :async) (rx/with-latest-from workspace-data-s) - (rx/merge-map (partial extract-frame-changes page-id)) - (rx/tap #(l/trc :hint "inconming change" :origin "notifications" :frame-id (dm/str %)))) + (rx/merge-map (partial extract-root-frame-changes page-id)) + (rx/tap #(l/trc :hint "incoming change" :origin "notifications" :frame-id (dm/str %)))) ;; PERSISTENCE CHANGES (->> stream @@ -270,7 +269,7 @@ (and (= file-id file-id) (= page-id page-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)) @@ -285,15 +284,13 @@ ;; and interrupt any ongoing update-thumbnail process ;; related to current frame-id (->> changes-s - (rx/map (fn [frame-id] - (clear-thumbnail file-id page-id frame-id "frame")))) + (rx/map #(clear-thumbnail file-id page-id % "frame"))) ;; Generate thumbnails in batchs, once user becomes ;; inactive for some instant (->> changes-s (rx/buffer-until notifier-s) (rx/mapcat #(into #{} %)) - (rx/map (fn [frame-id] - (request-thumbnail file-id page-id frame-id "frame"))))) + (rx/map #(request-thumbnail file-id page-id % "frame")))) (rx/take-until stopper-s)))))) diff --git a/frontend/src/debug.cljs b/frontend/src/debug.cljs index f944e0e70..56b36406a 100644 --- a/frontend/src/debug.cljs +++ b/frontend/src/debug.cljs @@ -243,6 +243,12 @@ (prn (str (:name frame) " - " (:id frame)))) 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 [shape-id] (st/emit! (dws/select-shape (uuid/uuid shape-id))))