From fc1db9b985936c62f555d44ee991d4162a460275 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 4 Dec 2023 13:24:59 +0100 Subject: [PATCH] :bug: Enhancement on old thumbnail invalidation after sync --- common/src/app/common/files/changes.cljc | 53 +++++++++++++++++++ .../app/main/data/workspace/libraries.cljs | 17 +++--- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index b5b3c6b446..d16b5de85f 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -804,3 +804,56 @@ [_ _] nil) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Copies changes detection +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Analyze one change and checks if if modifies any shape belonging to +;; a main or a copy. Return the ids of the mains or copies affected + +(defn- find-all-heads + "Go trough the parents and get all of them that are a head of a component." + [id objects] + (->> (cfh/get-parents-with-self objects id) + (filter ctk/instance-head?))) + +(defmulti heads-changed (fn [_ change] (:type change))) + +(defmethod heads-changed :mod-obj + [file-data {:keys [id page-id _component-id operations]}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + need-sync? (fn [operation] + ; Check if the shape has changed any + ; attribute that participates in components synchronization. + (and (= (:type operation) :set) + (get ctk/sync-attrs (:attr operation)))) + any-sync? (some need-sync? operations)] + (when any-sync? + (find-all-heads id (:objects page)))))) + +(defmethod heads-changed :mov-objects + [file-data {:keys [page-id _component-id parent-id shapes] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id)] + (concat + (find-all-heads parent-id (:objects page)) + (mapcat #(find-all-heads (:parent-id %) (:objects page)) shapes))))) + +(defmethod heads-changed :add-obj + [file-data {:keys [parent-id page-id _component-id] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id)] + (find-all-heads parent-id (:objects page))))) + +(defmethod heads-changed :del-obj + [file-data {:keys [id page-id _component-id] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id)] + (find-all-heads id (:objects page))))) + +(defmethod heads-changed :default + [_ _] + nil) + + diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index adce4bd8d1..fc08510d97 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -946,17 +946,16 @@ changes (pcb/concat-changes library-changes file-changes) - extract-shapes (fn [change] - (for [page-id [(:page-id change)] - id (:shapes change)] - (-> (get-in state [:workspace-data :pages-index page-id :objects id]) - (assoc :page-id page-id)))) - updated-copies (->> changes + find-heads (fn [change] + (->> (ch/heads-changed file change) + (map #(assoc %1 :page-id (:page-id change))))) + + + + updated-copies (->> changes :redo-changes - (filter #(= (:type %) :reg-objects)) - (mapcat extract-shapes) - (filter ctk/instance-head?) + (mapcat find-heads) distinct)] (log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes