🎉 Add lazy loading and storage/pointer-map support on workspace

This also rewrites the workspace load process making it a bit more
efficient independently if lazy loading is used.
This commit is contained in:
Andrey Antukh 2022-11-18 08:06:01 +01:00 committed by Andrés Moya
parent 6565655ac3
commit bbf95434d8
16 changed files with 387 additions and 349 deletions

View file

@ -9,7 +9,6 @@
[app.common.data.macros :as dm]
[app.common.logging :as log]
[app.common.pages.changes :as ch]
[app.common.transit :as t]
[app.config :as cf]
[okulary.core :as l]))
@ -31,29 +30,24 @@
[message]
message)
(defmethod handler :initialize-indices
[{:keys [file-raw] :as message}]
(defmethod handler :initialize-page-index
[{:keys [page] :as message}]
(swap! state update :pages-index assoc (:id page) page)
(handler (assoc message :cmd :selection/initialize-page-index))
(handler (assoc message :cmd :snaps/initialize-page-index)))
(let [data (-> (t/decode-str file-raw) :data)
message (assoc message :data data)]
(reset! state data)
(handler (assoc message :cmd :selection/initialize-index))
(handler (assoc message :cmd :snaps/initialize-index))))
(defmethod handler :update-page-indices
(defmethod handler :update-page-index
[{:keys [page-id changes] :as message}]
(let [old-page (dm/get-in @state [:pages-index page-id])]
(swap! state ch/process-changes changes false)
(let [new-page (dm/get-in @state [:pages-index page-id])
message (assoc message
:old-page old-page
:new-page new-page)]
(handler (-> message
(assoc :cmd :selection/update-index)))
(handler (-> message
(assoc :cmd :snaps/update-index))))))
(let [old-page (dm/get-in @state [:pages-index page-id])
new-page (-> state
(swap! ch/process-changes changes false)
(dm/get-in [:pages-index page-id]))
message (assoc message
:old-page old-page
:new-page new-page)]
(handler (assoc message :cmd :selection/update-page-index))
(handler (assoc message :cmd :snaps/update-page-index))))
(defmethod handler :configure
[{:keys [key val]}]

View file

@ -153,40 +153,34 @@
result)))
(defmethod impl/handler :selection/initialize-index
[{:keys [data] :as message}]
(letfn [(index-page [state page]
(let [id (:id page)
objects (:objects page)]
(assoc state id (create-index objects))))
(update-state [state]
(reduce index-page state (vals (:pages-index data))))]
(swap! state update-state)
(defmethod impl/handler :selection/initialize-page-index
[{:keys [page] :as message}]
(letfn [(add-page [state {:keys [id objects] :as page}]
(assoc state id (create-index objects)))]
(swap! state add-page page)
nil))
(defmethod impl/handler :selection/update-index
(defmethod impl/handler :selection/update-page-index
[{:keys [page-id old-page new-page] :as message}]
(let [old-objects (:objects old-page)
new-objects (:objects new-page)
update-page-index
(fn [index]
(let [old-bounds (:bounds index)
new-bounds (objects-bounds new-objects)]
(swap! state update page-id
(fn [index]
(let [old-objects (:objects old-page)
new-objects (:objects new-page)
old-bounds (:bounds index)
new-bounds (objects-bounds new-objects)]
;; If the new bounds are contained within the old bounds we can
;; update the index.
;; Otherwise we need to re-create it
(if (and (some? index)
(gsh/contains-selrect? old-bounds new-bounds))
(update-index index old-objects new-objects)
(create-index new-objects))))]
(swap! state update page-id update-page-index))
;; If the new bounds are contained within the old bounds
;; we can update the index. Otherwise we need to
;; re-create it.
(if (and (some? index)
(gsh/contains-selrect? old-bounds new-bounds))
(update-index index old-objects new-objects)
(create-index new-objects)))))
nil)
(defmethod impl/handler :selection/query
[{:keys [page-id rect frame-id full-frame? include-frames? ignore-groups? clip-children?]
:or {full-frame? false include-frames? false clip-children? true} :as message}]
:or {full-frame? false include-frames? false clip-children? true}
:as message}]
(when-let [index (get @state page-id)]
(query-index index rect frame-id full-frame? include-frames? ignore-groups? clip-children?)))

View file

@ -13,15 +13,12 @@
(defonce state (l/atom {}))
;; Public API
(defmethod impl/handler :snaps/initialize-index
[{:keys [data] :as message}]
(let [pages (vals (:pages-index data))]
(reset! state (reduce sd/add-page (sd/make-snap-data) pages)))
(defmethod impl/handler :snaps/initialize-page-index
[{:keys [page] :as message}]
(swap! state sd/add-page page)
nil)
(defmethod impl/handler :snaps/update-index
(defmethod impl/handler :snaps/update-page-index
[{:keys [old-page new-page] :as message}]
(swap! state sd/update-page old-page new-page)
nil)