fix: download graph

experiment/tanstack-table
Tienson Qin 2024-05-17 20:13:34 +08:00
parent 472685fced
commit 82db2351fe
4 changed files with 55 additions and 51 deletions

View File

@ -247,7 +247,10 @@
(defn- with-write-transit-str (defn- with-write-transit-str
[p] [p]
(p/chain p ldb/write-transit-str)) (p/chain p
(fn [result]
(let [result (when-not (= result @worker-state/*state) result)]
(ldb/write-transit-str result)))))
#_:clj-kondo/ignore #_:clj-kondo/ignore
(defclass DBWorker (defclass DBWorker

View File

@ -8,61 +8,61 @@
[frontend.util :as util])) [frontend.util :as util]))
(defn invoke-hooks (defn invoke-hooks
[{:keys [_request-id tx-meta tx-data deleted-block-uuids affected-keys blocks]}] [{:keys [_request-id repo tx-meta tx-data deleted-block-uuids affected-keys blocks]}]
;; (prn :debug ;; (prn :debug
;; :request-id request-id ;; :request-id request-id
;; :tx-meta tx-meta ;; :tx-meta tx-meta
;; :tx-data tx-data) ;; :tx-data tx-data)
(let [{:keys [from-disk? new-graph? initial-pages? end?]} tx-meta (let [{:keys [from-disk? new-graph? initial-pages? end?]} tx-meta
repo (state/get-current-repo)
tx-report {:tx-meta tx-meta tx-report {:tx-meta tx-meta
:tx-data tx-data} :tx-data tx-data}]
conn (db/get-db repo false)] (when (= repo (state/get-current-repo))
(cond (let [conn (db/get-db repo false)]
initial-pages? (cond
(do initial-pages?
(util/profile "transact initial-pages" (d/transact! conn tx-data tx-meta)) (do
(when end? (util/profile "transact initial-pages" (d/transact! conn tx-data tx-meta))
(state/pub-event! [:init/commands]) (when end?
(react/clear-query-state!) (state/pub-event! [:init/commands])
(ui-handler/re-render-root!))) (react/clear-query-state!)
(ui-handler/re-render-root!)))
(or from-disk? new-graph?) (or from-disk? new-graph?)
(do (do
(d/transact! conn tx-data tx-meta) (d/transact! conn tx-data tx-meta)
(react/clear-query-state!) (react/clear-query-state!)
(ui-handler/re-render-root!)) (ui-handler/re-render-root!))
:else :else
(do (do
(let [tx-data' (if (contains? #{:create-property-text-block :insert-blocks} (:outliner-op tx-meta)) (let [tx-data' (if (contains? #{:create-property-text-block :insert-blocks} (:outliner-op tx-meta))
(let [update-blocks-fully-loaded (keep (fn [datom] (when (= :block/uuid (:a datom)) (let [update-blocks-fully-loaded (keep (fn [datom] (when (= :block/uuid (:a datom))
{:db/id (:e datom) {:db/id (:e datom)
:block.temp/fully-loaded? true})) tx-data)] :block.temp/fully-loaded? true})) tx-data)]
(concat update-blocks-fully-loaded tx-data)) (concat update-blocks-fully-loaded tx-data))
tx-data)] tx-data)]
(d/transact! conn tx-data' tx-meta)) (d/transact! conn tx-data' tx-meta))
(when-not (:graph/importing @state/state) (when-not (:graph/importing @state/state)
;; safe to edit the next block now since other blocks (e.g. prev editing block) ;; safe to edit the next block now since other blocks (e.g. prev editing block)
;; has been saved to the db now ;; has been saved to the db now
(when-let [next-edit-block @(:editor/next-edit-block @state/state)] (when-let [next-edit-block @(:editor/next-edit-block @state/state)]
(let [{:keys [block pos]} next-edit-block] (let [{:keys [block pos]} next-edit-block]
(editor-handler/edit-block! block pos) (editor-handler/edit-block! block pos)
(state/set-state! :editor/next-edit-block nil))) (state/set-state! :editor/next-edit-block nil)))
(react/refresh! repo affected-keys) (react/refresh! repo affected-keys)
(state/set-state! :editor/start-pos nil) (state/set-state! :editor/start-pos nil)
(when (and state/lsp-enabled? (when (and state/lsp-enabled?
(seq blocks) (seq blocks)
(<= (count blocks) 1000)) (<= (count blocks) 1000))
(state/pub-event! [:plugin/hook-db-tx (state/pub-event! [:plugin/hook-db-tx
{:blocks blocks {:blocks blocks
:deleted-block-uuids deleted-block-uuids :deleted-block-uuids deleted-block-uuids
:tx-data (:tx-data tx-report) :tx-data (:tx-data tx-report)
:tx-meta (:tx-meta tx-report)}]))))) :tx-meta (:tx-meta tx-report)}])))))))
(when (= (:outliner-op tx-meta) :delete-page) (when (= (:outliner-op tx-meta) :delete-page)
(state/pub-event! [:page/deleted repo (:deleted-page tx-meta) (:file-path tx-meta) tx-meta])) (state/pub-event! [:page/deleted repo (:deleted-page tx-meta) (:file-path tx-meta) tx-meta]))

View File

@ -60,7 +60,7 @@ generate undo ops.")
(let [{:keys [from-disk?]} tx-meta (let [{:keys [from-disk?]} tx-meta
result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context)) result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
tx-report' (:tx-report result)] tx-report' (:tx-report result)]
(when result (when (and result (not (:rtc-download-graph? tx-meta)))
(let [data (merge (let [data (merge
{:request-id (:request-id tx-meta) {:request-id (:request-id tx-meta)
:repo repo :repo repo
@ -71,13 +71,13 @@ generate undo ops.")
(when-not from-disk? (when-not from-disk?
(p/do! (p/do!
(let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report') (let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report')
^js wo (worker-state/get-worker-object)] ^js wo (worker-state/get-worker-object)]
(when wo (when wo
(when (seq blocks-to-remove-set) (when (seq blocks-to-remove-set)
(.search-delete-blocks wo repo (bean/->js blocks-to-remove-set))) (.search-delete-blocks wo repo (bean/->js blocks-to-remove-set)))
(when (seq blocks-to-add) (when (seq blocks-to-add)
(.search-upsert-blocks wo repo (bean/->js blocks-to-add)))))))))) (.search-upsert-blocks wo repo (bean/->js blocks-to-add))))))))))
(defn listen-db-changes! (defn listen-db-changes!

View File

@ -247,4 +247,5 @@
(op-mem-layer/update-graph-uuid! repo graph-uuid) (op-mem-layer/update-graph-uuid! repo graph-uuid)
(m/? (op-mem-layer/new-task--sync-to-idb repo)) (m/? (op-mem-layer/new-task--sync-to-idb repo))
(m/? (c.m/await-promise (.storeMetadata worker-obj repo (pr-str {:graph/uuid graph-uuid})))) (m/? (c.m/await-promise (.storeMetadata worker-obj repo (pr-str {:graph/uuid graph-uuid}))))
(worker-state/set-rtc-downloading-graph! false)))))) (worker-state/set-rtc-downloading-graph! false)
nil)))))