Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Andrey Antukh 2025-02-14 10:35:29 +01:00
commit 37855bfe7f
7 changed files with 88 additions and 66 deletions

View file

@ -431,8 +431,12 @@
process-file process-file
(fn [file-id idx tpoint] (fn [file-id idx tpoint]
(let [thread-id (px/get-thread-id)]
(try (try
(l/trc :hint "process:file:start" :file-id (str file-id) :index idx) (l/trc :hint "process:file:start"
:tid thread-id
:file-id (str file-id)
:index idx)
(let [system (assoc main/system ::db/rollback rollback?)] (let [system (assoc main/system ::db/rollback rollback?)]
(db/tx-run! system (fn [system] (db/tx-run! system (fn [system]
(binding [h/*system* system] (binding [h/*system* system]
@ -440,16 +444,27 @@
(catch Throwable cause (catch Throwable cause
(l/wrn :hint "unexpected error on processing file (skiping)" (l/wrn :hint "unexpected error on processing file (skiping)"
:tid thread-id
:file-id (str file-id) :file-id (str file-id)
:index idx :index idx
:cause cause)) :cause cause))
(finally (finally
(when-let [pause (:pause opts)]
(Thread/sleep (int pause)))
(ps/release! sjobs) (ps/release! sjobs)
(let [elapsed (dt/format-duration (tpoint))] (let [elapsed (dt/format-duration (tpoint))]
(l/trc :hint "process:file:end" (l/trc :hint "process:file:end"
:tid thread-id
:file-id (str file-id) :file-id (str file-id)
:index idx :index idx
:elapsed elapsed))))) :elapsed elapsed))))))
process-file*
(fn [idx file-id]
(ps/acquire! sjobs)
(px/run! executor (partial process-file file-id idx (dt/tpoint)))
(inc idx))
process-files process-files
(fn [{:keys [::db/conn] :as system}] (fn [{:keys [::db/conn] :as system}]
@ -457,14 +472,12 @@
(db/exec! conn ["SET idle_in_transaction_session_timeout = 0"]) (db/exec! conn ["SET idle_in_transaction_session_timeout = 0"])
(try (try
(reduce (fn [idx file-id] (->> (db/plan conn [query])
(ps/acquire! sjobs) (transduce (comp
(px/run! executor (partial process-file file-id idx (dt/tpoint)))
(inc idx))
0
(->> (db/cursor conn [query] {:chunk-size 1})
(take max-items) (take max-items)
(map :id))) (map :id))
(completing process-file*)
0))
(finally (finally
;; Close and await tasks ;; Close and await tasks
(pu/close! executor))))] (pu/close! executor))))]

View file

@ -469,11 +469,10 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [file (dissoc file :data)]
(-> state (-> state
(assoc-in [:files id] file) (assoc-in [:files id] file)
(assoc-in [:recent-files id] file) (assoc-in [:recent-files id] file)
(update-in [:projects project-id :count] inc)))))) (update-in [:projects project-id :count] inc)))))
(defn create-file (defn create-file
[{:keys [project-id name] :as params}] [{:keys [project-id name] :as params}]

View file

@ -319,6 +319,8 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(dissoc :files)
(dissoc :workspace-ready)
(assoc :recent-colors (:recent-colors storage/user)) (assoc :recent-colors (:recent-colors storage/user))
(assoc :recent-fonts (:recent-fonts storage/user)) (assoc :recent-fonts (:recent-fonts storage/user))
(assoc :current-file-id file-id) (assoc :current-file-id file-id)
@ -393,9 +395,11 @@
(dissoc (dissoc
:current-file-id :current-file-id
:workspace-editor-state :workspace-editor-state
:files
:workspace-media-objects :workspace-media-objects
:workspace-persistence :workspace-persistence
:workspace-presence :workspace-presence
:workspace-ready
:workspace-undo) :workspace-undo)
(update :workspace-global dissoc :read-only?) (update :workspace-global dissoc :read-only?)
(assoc-in [:workspace-global :options-mode] :design))) (assoc-in [:workspace-global :options-mode] :design)))
@ -423,18 +427,18 @@
(defmethod ptk/resolve ::reload-current-file [_ _] (reload-current-file)) (defmethod ptk/resolve ::reload-current-file [_ _] (reload-current-file))
(defn initialize-page (defn initialize-page
[file-id page-id] [page-id]
(assert (uuid? file-id) "expected valid uuid for `file-id`") (assert (uuid? page-id) "expected valid uuid for `page-id`")
(ptk/reify ::initialize-page (ptk/reify ::initialize-page
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(if-let [page (dsh/lookup-page state file-id page-id)] (if-let [{:keys [id] :as page} (dsh/lookup-page state page-id)]
;; we maintain a cache of page state for user convenience with the exception of the ;; we maintain a cache of page state for user convenience with the exception of the
;; selection; when user abandon the current page, the selection is lost ;; selection; when user abandon the current page, the selection is lost
(let [local (dm/get-in state [:workspace-cache [file-id page-id]] default-workspace-local)] (let [local (dm/get-in state [:workspace-cache id] default-workspace-local)]
(-> state (-> state
(assoc :current-page-id page-id) (assoc :current-page-id id)
(assoc :workspace-local (assoc local :selected (d/ordered-set))) (assoc :workspace-local (assoc local :selected (d/ordered-set)))
(assoc :workspace-trimmed-page (dm/select-keys page [:id :name])) (assoc :workspace-trimmed-page (dm/select-keys page [:id :name]))
@ -446,25 +450,24 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(if (dsh/lookup-page state file-id page-id) (if (dsh/lookup-page state page-id)
(let [file-id (:current-file-id state)]
(rx/of (preload-data-uris page-id) (rx/of (preload-data-uris page-id)
(dwth/watch-state-changes file-id page-id) (dwth/watch-state-changes file-id page-id)
(dwl/watch-component-changes)) (dwl/watch-component-changes)))
(rx/of (dcm/go-to-workspace :file-id file-id ::rt/replace true)))))) (rx/of (dcm/go-to-workspace))))))
(defn finalize-page (defn finalize-page
[file-id page-id] [page-id]
(assert (uuid? file-id) "expected valid uuid for `file-id`")
(assert (uuid? page-id) "expected valid uuid for `page-id`") (assert (uuid? page-id) "expected valid uuid for `page-id`")
(ptk/reify ::finalize-page (ptk/reify ::finalize-page
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [local (-> (:workspace-local state) (let [local (-> (:workspace-local state)
(dissoc :edition :edit-path :selected)) (dissoc :edition :edit-path :selected))
exit? (not= :workspace (rt/lookup-name state)) exit? (not= :workspace (dm/get-in state [:route :data :name]))
state (-> state state (-> state
(update :workspace-cache assoc [file-id page-id] local) (update :workspace-cache assoc page-id local)
(dissoc :current-page-id (dissoc :current-page-id
:workspace-local :workspace-local
:workspace-trimmed-page :workspace-trimmed-page

View file

@ -120,11 +120,6 @@
([id params & {:as options}] ([id params & {:as options}]
(navigate id params options))) (navigate id params options)))
(defn lookup-name
[state]
(dm/get-in state [:route :data :name]))
;; FIXME: rename to lookup-params
(defn get-params (defn get-params
[state] [state]
(dm/get-in state [:route :params :query])) (dm/get-in state [:route :params :query]))

View file

@ -127,6 +127,7 @@
{::mf/props :obj {::mf/props :obj
::mf/private true} ::mf/private true}
[{:keys [team-id children]}] [{:keys [team-id children]}]
(mf/with-effect [team-id] (mf/with-effect [team-id]
(st/emit! (dtm/initialize-team team-id)) (st/emit! (dtm/initialize-team team-id))
(fn [] (fn []

View file

@ -9,6 +9,7 @@
(:require (:require
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.main.data.common :as dcm] [app.main.data.common :as dcm]
[app.main.data.helpers :as dsh]
[app.main.data.persistence :as dps] [app.main.data.persistence :as dps]
[app.main.data.plugins :as dpl] [app.main.data.plugins :as dpl]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
@ -42,6 +43,13 @@
[okulary.core :as l] [okulary.core :as l]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(defn- make-workspace-ready-ref
[file-id]
(l/derived (fn [state]
(and (= file-id (:workspace-ready state))
(some? (dsh/lookup-file-data state file-id))))
st/state))
(mf/defc workspace-content* (mf/defc workspace-content*
{::mf/private true} {::mf/private true}
[{:keys [file layout page wglobal]}] [{:keys [file layout page wglobal]}]
@ -130,18 +138,22 @@
key (events/listen globals/window "blur" focus-out)] key (events/listen globals/window "blur" focus-out)]
(partial events/unlistenByKey key))) (partial events/unlistenByKey key)))
(mf/with-effect [file page-id] (mf/with-effect [page-id]
(st/emit! (dw/initialize-page (:id file) page-id)) (if (some? page-id)
(st/emit! (dw/initialize-page page-id))
(st/emit! (dcm/go-to-workspace ::rt/replace true)))
(fn [] (fn []
(when page-id (when (some? page-id)
(st/emit! (dw/finalize-page (:id file) page-id))))) (st/emit! (dw/finalize-page page-id)))))
(if (some? page) (if (some? page)
[:> workspace-content* {:file file [:> workspace-content* {:file file
:page page :page page
:wglobal wglobal :wglobal wglobal
:layout layout}] :layout layout}]
[:> workspace-loader*]))) [:& workspace-loader*])))
(def ^:private ref:file-without-data (def ^:private ref:file-without-data
(l/derived (fn [file] (l/derived (fn [file]
@ -169,6 +181,10 @@
read-only? (mf/deref refs/workspace-read-only?) read-only? (mf/deref refs/workspace-read-only?)
read-only? (or read-only? (not (:can-edit permissions))) read-only? (or read-only? (not (:can-edit permissions)))
ready* (mf/with-memo [file-id]
(make-workspace-ready-ref file-id))
ready? (mf/deref ready*)
design-tokens? (features/use-feature "design-tokens/v1") design-tokens? (features/use-feature "design-tokens/v1")
background-color (:background-color wglobal)] background-color (:background-color wglobal)]
@ -191,10 +207,6 @@
(st/emit! ::dps/force-persist (st/emit! ::dps/force-persist
(dw/finalize-workspace file-id)))) (dw/finalize-workspace file-id))))
(mf/with-effect [file page-id]
(when-not page-id
(st/emit! (dcm/go-to-workspace :file-id file-id ::rt/replace true))))
[:> (mf/provider ctx/current-project-id) {:value project-id} [:> (mf/provider ctx/current-project-id) {:value project-id}
[:> (mf/provider ctx/current-file-id) {:value file-id} [:> (mf/provider ctx/current-file-id) {:value file-id}
[:> (mf/provider ctx/current-page-id) {:value page-id} [:> (mf/provider ctx/current-page-id) {:value page-id}
@ -207,9 +219,8 @@
:touch-action "none"}} :touch-action "none"}}
[:> context-menu*] [:> context-menu*]
(if (some? file) (if ^boolean ready?
[:> workspace-page* [:> workspace-page* {:page-id page-id
{:page-id page-id
:file file :file file
:wglobal wglobal :wglobal wglobal
:layout layout}] :layout layout}]

View file

@ -63,10 +63,10 @@
target-container-id (or target-container-id (:parent-id shape))] target-container-id (or target-container-id (:parent-id shape))]
(filter some? (filter some?
[(when target-page-id (dw/initialize-page (:id file) target-page-id)) [(when target-page-id (dw/initialize-page target-page-id))
(dws/select-shape target-container-id) (dws/select-shape target-container-id)
(dw/paste-shapes pdata) (dw/paste-shapes pdata)
(when target-page-id (dw/initialize-page (:id file) (:id page)))]))) (when target-page-id (dw/initialize-page (:id page)))])))
(defn- sync-file [file] (defn- sync-file [file]
(map (fn [component-tag] (map (fn [component-tag]