mirror of
https://github.com/penpot/penpot.git
synced 2026-11-06 10:00:38 +00:00
* ⚡ Keep only the shape data the worker reads The worker kept a full copy of the current page for its selection and snap indexes. It now keeps only the attributes the indexes and the change replay read, and re-indexes only the shapes that changed. On a 52k-shape page the worker heap goes from 698 MB to 286 MB. Closes #12740 AI-assisted-by: claude-opus-5-5 * ♻️ Share the worker re-trim with its replay test The worker and its replay test now share `retrim-objects`. AI-assisted-by: claude-opus-5-5
55 lines
2.1 KiB
Clojure
55 lines
2.1 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns common-tests.files.page-diff-test
|
|
(:require
|
|
[app.common.files.page-diff :as diff]
|
|
[app.common.types.shape :as cts]
|
|
[app.common.uuid :as uuid]
|
|
[clojure.test :as t]))
|
|
|
|
(def ^:private check-attrs [:frame-id :x :y :width :height :hidden :selrect :grids])
|
|
|
|
(def ^:private rect-a-id (uuid/custom 50 1))
|
|
(def ^:private rect-b-id (uuid/custom 50 2))
|
|
(def ^:private rect-c-id (uuid/custom 50 3))
|
|
(def ^:private guide-id (uuid/custom 50 4))
|
|
|
|
(defn- make-rect
|
|
[id x]
|
|
(cts/setup-shape {:id id :type :rect :name "rect"
|
|
:frame-id uuid/zero :parent-id uuid/zero
|
|
:x x :y 0 :width 10 :height 10}))
|
|
|
|
(def ^:private old-page
|
|
{:id (uuid/custom 50 10)
|
|
:objects {rect-a-id (make-rect rect-a-id 0)
|
|
rect-b-id (make-rect rect-b-id 0)}})
|
|
|
|
(def ^:private new-page
|
|
{:id (uuid/custom 50 10)
|
|
:objects {rect-a-id (make-rect rect-a-id 50)
|
|
rect-b-id (make-rect rect-b-id 50)
|
|
rect-c-id (make-rect rect-c-id 0)}
|
|
:guides {guide-id {:id guide-id :axis :x :position 10}}})
|
|
|
|
(t/deftest diff-with-every-id-reports-every-change
|
|
(let [result (diff/calculate-page-diff old-page new-page check-attrs
|
|
#{rect-a-id rect-b-id rect-c-id})]
|
|
(t/is (= #{rect-a-id rect-b-id}
|
|
(into #{} (map (comp :id second)) (:updated-shapes result))))
|
|
(t/is (= [rect-c-id] (mapv :id (:new-shapes result))))
|
|
(t/is (= [guide-id] (mapv :id (:new-guides result))))))
|
|
|
|
(t/deftest diff-ignores-objects-outside-the-given-ids
|
|
(let [result (diff/calculate-page-diff old-page new-page check-attrs #{rect-a-id})]
|
|
(t/is (= [rect-a-id] (mapv (comp :id second) (:updated-shapes result))))
|
|
(t/is (= [] (:new-shapes result)))))
|
|
|
|
(t/deftest diff-always-compares-every-guide
|
|
(let [result (diff/calculate-page-diff old-page new-page check-attrs #{})]
|
|
(t/is (= [guide-id] (mapv :id (:new-guides result))))))
|