diff --git a/backend/dev/user.clj b/backend/dev/user.clj index 4f47934a8..2b881cc4a 100644 --- a/backend/dev/user.clj +++ b/backend/dev/user.clj @@ -95,3 +95,33 @@ [{:v1 (alength (blob/encode data {:version 1})) :v2 (alength (blob/encode data {:version 2})) :v3 (alength (blob/encode data {:version 3}))}])) + +(defn update-page-1 + [data] + (letfn [(find-empty-groups [objects] + (->> (vals objects) + (filter (fn [shape] + (and (= :group (:type shape)) + (or (empty? (:shapes shape)) + (every? (fn [child-id] + (not (contains? objects child-id))) + (:shapes shape)))))) + (map :id))) + + (update-page [[page-id page]] + (let [objects (:objects page) + eids (find-empty-groups objects)] + + (map (fn [id] + {:type :del-obj + :page-id page-id + :id id}) + eids)))] + (loop [i 0 data data] + (let [changes (mapcat update-page (:pages-index data))] + (prn "==== loop " i " ====") + (clojure.pprint/pprint changes) + (if (seq changes) + (recur (inc i) + (app.common.pages.changes/process-changes data changes)) + data))))) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index 7a1216780..861b5c0b4 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -222,3 +222,30 @@ (update :pages-index #(d/mapm clean-container %)) (d/update-when :components #(d/mapm clean-container %))))) +(defmethod migrate 9 + [data] + (letfn [(find-empty-groups [objects] + (->> (vals objects) + (filter (fn [shape] + (and (= :group (:type shape)) + (or (empty? (:shapes shape)) + (every? (fn [child-id] + (not (contains? objects child-id))) + (:shapes shape)))))) + (map :id))) + + (update-page [[page-id page]] + (let [objects (:objects page) + eids (find-empty-groups objects)] + + (map (fn [id] + {:type :del-obj + :page-id page-id + :id id}) + eids)))] + + (loop [data data] + (let [changes (mapcat update-page (:pages-index data))] + (if (seq changes) + (recur (cp/process-changes data changes)) + data)))))