From 661a916a5f53dc61140add681c94c82f4a39686d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 21 Aug 2023 18:03:49 +0200 Subject: [PATCH] :bug: Fix reference counting of file-media objects in :fill-image attr --- backend/src/app/rpc/commands/binfile.clj | 10 ++++++---- backend/src/app/tasks/file_gc.clj | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/src/app/rpc/commands/binfile.clj b/backend/src/app/rpc/commands/binfile.clj index 72cb419c9..632239f2b 100644 --- a/backend/src/app/rpc/commands/binfile.clj +++ b/backend/src/app/rpc/commands/binfile.clj @@ -516,6 +516,9 @@ :media (count media) ::l/sync? true) + (doseq [item media] + (l/debug :hint "write penpot file media object" :id (:id item) ::l/sync? true)) + (doto output (write-obj! file) (write-obj! media)) @@ -770,7 +773,7 @@ (defn- lookup-index [id] (let [val (get-in @*state* [:index id])] - (l/trace :fn "lookup-index" :id id :val val ::l/sync? true) + (l/debug :fn "lookup-index" :id id :val val ::l/sync? true) (when (and (not (::ignore-index-errors? *options*)) (not val)) (ex/raise :type :validation :code :incomplete-index @@ -783,7 +786,7 @@ index index] (if-let [id (first items)] (let [new-id (if (::overwrite? *options*) id (uuid/next))] - (l/trace :fn "update-index" :id id :new-id new-id ::l/sync? true) + (l/debug :fn "update-index" :id id :new-id new-id ::l/sync? true) (recur (rest items) (assoc index id new-id))) index))) @@ -801,8 +804,7 @@ (update-in [:metadata :id] lookup-index) ;; Relink paths with fill image - (and (map? (:fill-image form)) - (= :path (:type form))) + (map? (:fill-image form)) (update-in [:fill-image :id] lookup-index) ;; This covers old shapes and the new :fills. diff --git a/backend/src/app/tasks/file_gc.clj b/backend/src/app/tasks/file_gc.clj index 9b9c2134a..ac83404a1 100644 --- a/backend/src/app/tasks/file_gc.clj +++ b/backend/src/app/tasks/file_gc.clj @@ -113,8 +113,15 @@ (mapcat vals) (keep (fn [{:keys [type] :as obj}] (case type - :path (get-in obj [:fill-image :id]) + :path (get-in obj [:fill-image :id]) + :bool (get-in obj [:fill-image :id]) + ;; NOTE: because of some bug, we ended with + ;; many shape types having the ability to + ;; have fill-image attribute (which initially + ;; designed for :path shapes). + :group (get-in obj [:fill-image :id]) :image (get-in obj [:metadata :id]) + nil)))) pages (concat (vals (:pages-index data))