From 7b8d1275833263a4557f3a896960e32a26bd1916 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 21 Jun 2024 11:47:26 +0200 Subject: [PATCH 1/2] :bug: Fix incorrect frame change detection on thumbnails generation --- .../app/main/data/workspace/thumbnails.cljs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index c4cde6e2de..ab28b902c8 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -10,6 +10,7 @@ [app.common.files.helpers :as cfh] [app.common.logging :as l] [app.common.thumbnails :as thc] + [app.common.uuid :as uuid] [app.config :as cf] [app.main.data.changes :as dch] [app.main.data.persistence :as-alias dps] @@ -192,8 +193,8 @@ :mov-objects (->> (:shapes change) (map #(vector page-id %))) [])) - get-frame-id - (fn [[_ id]] + get-frame-ids + (fn get-frame-ids [id] (let [old-objects (wsh/lookup-data-objects old-data page-id) new-objects (wsh/lookup-data-objects new-data page-id) @@ -208,12 +209,21 @@ (conj old-frame-id) (cfh/root-frame? new-objects new-frame-id) - (conj new-frame-id))))] + (conj new-frame-id) + + (and (uuid? (:frame-id old-shape)) + (not= uuid/zero (:frame-id old-shape))) + (into (get-frame-ids (:frame-id old-shape))) + + (and (uuid? (:frame-id new-shape)) + (not= uuid/zero (:frame-id new-shape))) + (into (get-frame-ids (:frame-id new-shape))))))] (into #{} (comp (mapcat extract-ids) (filter (fn [[page-id']] (= page-id page-id'))) - (mapcat get-frame-id)) + (map (fn [[_ id]] id)) + (mapcat get-frame-ids)) changes))) (defn watch-state-changes From b25a9f8626a50c73b91374dedab8e3279c3c8cb9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 21 Jun 2024 12:09:50 +0200 Subject: [PATCH 2/2] :bug: Return back to use blob uris for transient thumbnails --- .../app/main/data/workspace/thumbnails.cljs | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index ab28b902c8..625c207c62 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -11,7 +11,6 @@ [app.common.logging :as l] [app.common.thumbnails :as thc] [app.common.uuid :as uuid] - [app.config :as cf] [app.main.data.changes :as dch] [app.main.data.persistence :as-alias dps] [app.main.data.workspace.notifications :as-alias wnt] @@ -20,7 +19,6 @@ [app.main.refs :as refs] [app.main.render :as render] [app.main.repo :as rp] - [app.util.http :as http] [app.util.queue :as q] [app.util.time :as tp] [app.util.timers :as tm] @@ -150,34 +148,34 @@ ptk/WatchEvent (watch [_ state stream] (l/dbg :hint "update thumbnail" :requester requester :object-id object-id :tag tag) - ;; Send the update to the back-end - (->> (request-thumbnail state file-id page-id frame-id tag) - (rx/mapcat (fn [blob] - ;; Send the data to backend - (let [params {:file-id file-id - :object-id object-id - :media blob - :tag (or tag "frame")}] - (rp/cmd! :create-file-object-thumbnail params)))) + (let [tp (tp/tpoint-ms)] + ;; Send the update to the back-end + (->> (request-thumbnail state file-id page-id frame-id tag) + (rx/mapcat (fn [blob] + (let [uri (wapi/create-uri blob) + params {:file-id file-id + :object-id object-id + :media blob + :tag (or tag "frame")}] - (rx/mapcat (fn [{:keys [object-id media-id]}] - (let [uri (cf/resolve-media media-id)] - ;; We perform this request just for - ;; populate the browser CACHE and avoid - ;; unnecesary image flickering - (->> (http/send! {:uri uri :method :get}) - (rx/map #(assoc-thumbnail object-id uri)))))) + (rx/merge + (rx/of (assoc-thumbnail object-id uri)) + (->> (rp/cmd! :create-file-object-thumbnail params) + (rx/catch rx/empty) + (rx/ignore)))))) - (rx/catch (fn [cause] - (.error js/console cause) - (rx/empty))) + (rx/catch (fn [cause] + (.error js/console cause) + (rx/empty))) - ;; We cancel all the stream if user starts editing while - ;; thumbnail is generating - (rx/take-until - (->> stream - (rx/filter (ptk/type? ::clear-thumbnail)) - (rx/filter #(= (deref %) object-id))))))))) + (rx/tap #(l/trc :hint "thumbnail updated" :elapsed (dm/str (tp) "ms"))) + + ;; We cancel all the stream if user starts editing while + ;; thumbnail is generating + (rx/take-until + (->> stream + (rx/filter (ptk/type? ::clear-thumbnail)) + (rx/filter #(= (deref %) object-id)))))))))) (defn- extract-root-frame-changes "Process a changes set in a commit to extract the frames that are changing"