🐛 Fix problem when forcing persistence on screen change

This commit is contained in:
alonso.torres 2023-01-05 16:18:48 +01:00
parent c459c56f37
commit 672cfa4ecc

View file

@ -93,29 +93,32 @@
(->> (rx/from-atom commits)
(rx/filter (complement empty?))
(rx/sample-when
(rx/merge
(rx/filter #(= ::force-persist %) stream)
(->> (rx/merge
(rx/interval 5000)
(rx/filter #(= ::force-persist %) stream)
(->> (rx/from-atom commits)
(rx/filter (complement empty?))
(rx/debounce 2000)))
;; Not sample while saving so there are no race conditions
(rx/filter #(not @saving?))))
(rx/filter #(not @saving?)))))
(rx/tap #(reset! commits []))
(rx/tap on-saving)
(rx/mapcat (fn [changes]
;; NOTE: this is needed for don't start the
;; next persistence before this one is
;; finished.
(if-let [file-revn (dm/get-in @st/state [:workspace-file :revn])]
(rx/merge
(->> (rx/of (persist-changes file-id changes commits))
(->> (rx/of (persist-changes file-id file-revn changes commits))
(rx/observe-on :async))
(->> stream
;; We wait for every change to be persisted
(rx/filter (ptk/type? ::shapes-changes-persisted-finished))
(rx/take 1)
(rx/tap on-saved)
(rx/ignore)))))
(rx/ignore)))
(rx/empty))))
(rx/take-until (rx/delay 100 stoper))
(rx/finalize (fn []
(log/debug :hint "finalize persistence: save loop"))))
@ -132,7 +135,7 @@
(log/debug :hint "finalize persistence: synchronous save loop")))))))))
(defn persist-changes
[file-id changes pending-commits]
[file-id file-revn changes pending-commits]
(log/debug :hint "persist changes" :changes (count changes))
(us/verify ::us/uuid file-id)
(ptk/reify ::persist-changes
@ -146,14 +149,12 @@
(features/active-feature? state :components-v2)
(conj "components/v2"))
sid (:session-id state)
file (get state :workspace-file)
params {:id (:id file)
:revn (:revn file)
params {:id file-id
:revn file-revn
:session-id sid
:changes-with-metadata (into [] changes)
:features features}]
(when (= file-id (:id params))
(->> (rp/cmd! :update-file params)
(rx/mapcat (fn [lagged]
(log/debug :hint "changes persisted" :lagged (count lagged))
@ -163,14 +164,14 @@
commits
(->> @pending-commits
(map #(assoc % :revn (:revn file))))]
(map #(assoc % :revn file-revn)))]
(rx/concat
(rx/merge
(->> (rx/from frame-updates)
(rx/mapcat (fn [[page-id frames]]
(->> frames (map #(vector page-id %)))))
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail (:id file) page-id frame-id))))
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail file-id page-id frame-id))))
(->> (rx/from (concat lagged commits))
(rx/merge-map
@ -187,7 +188,7 @@
(if (= :authentication (:type cause))
(rx/empty)
(rx/of (rt/assign-exception cause)))
(rx/throw cause))))))))))
(rx/throw cause)))))))))
;; Event to be thrown after the changes have been persisted
(defn shapes-changes-persisted-finished