From 9fcb4216b6f207274ab1079c78c5d7ef43c870e2 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 22 May 2024 17:22:47 +0200 Subject: [PATCH] :zap: Improved performance to update layout --- frontend/src/app/main/data/workspace/shape_layout.cljs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 765973787..76a346c00 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -119,7 +119,14 @@ (->> stream (rx/filter (ptk/type? :layout/update)) (rx/map deref) - (rx/map #(update-layout-positions %)) + ;; We buffer the updates to the layout so if there are many changes at the same time + ;; they are process together. It will get a better performance. + (rx/buffer-time 100) + (rx/filter #(d/not-empty? %)) + (rx/map + (fn [data] + (let [ids (reduce #(into %1 (:ids %2)) #{} data)] + (update-layout-positions {:ids ids})))) (rx/take-until stopper)))))) (defn finalize