mirror of
https://github.com/logseq/logseq.git
synced 2026-05-27 22:24:09 +00:00
fix: rebuild db from datoms if there're missing addresses
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
[frontend.handler.file-based.property.util :as property-util]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[promesa.core :as p]))
|
||||
@@ -126,19 +127,25 @@
|
||||
(p/promise e)
|
||||
|
||||
:else
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/get-blocks graph
|
||||
[{:id id :opts opts}])
|
||||
{:keys [block children]} (first result)]
|
||||
(when-not skip-transact?
|
||||
(let [conn (db/get-db graph false)
|
||||
block-and-children (if block (cons block children) children)
|
||||
affected-keys [[:frontend.worker.react/block (:db/id block)]]
|
||||
tx-data (remove (fn [b] (:block.temp/fully-loaded? (db/entity (:db/id b)))) block-and-children)]
|
||||
(when (seq tx-data) (d/transact! conn tx-data))
|
||||
(when-not skip-refresh?
|
||||
(react/refresh-affected-queries! graph affected-keys))))
|
||||
(->
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/get-blocks graph
|
||||
[{:id id :opts opts}])
|
||||
{:keys [block children]} (first result)]
|
||||
(when-not skip-transact?
|
||||
(let [conn (db/get-db graph false)
|
||||
block-and-children (if block (cons block children) children)
|
||||
affected-keys [[:frontend.worker.react/block (:db/id block)]]
|
||||
tx-data (->> (remove (fn [b] (:block.temp/fully-loaded? (db/entity (:db/id b)))) block-and-children)
|
||||
(common-util/fast-remove-nils)
|
||||
(remove empty?))]
|
||||
(when (seq tx-data) (d/transact! conn tx-data))
|
||||
(when-not skip-refresh?
|
||||
(react/refresh-affected-queries! graph affected-keys))))
|
||||
|
||||
(if children-only? children block)))))
|
||||
(if children-only? children block))
|
||||
(p/catch (fn [error]
|
||||
(js/console.error error)
|
||||
(throw (ex-info "get-block error" {:block id-uuid-or-name}))))))))
|
||||
|
||||
(defn <get-blocks
|
||||
[graph ids* & {:as opts}]
|
||||
|
||||
@@ -174,7 +174,8 @@
|
||||
(worker-util/post-message :capture-error
|
||||
{:error "db-missing-addresses"
|
||||
:payload {:missing-addresses missing-addresses}})
|
||||
(prn :error :missing-addresses missing-addresses))))
|
||||
(prn :error :missing-addresses missing-addresses))
|
||||
missing-addresses))
|
||||
|
||||
(defn upsert-addr-content!
|
||||
"Upsert addr+data-seq. Update sqlite-cli/upsert-addr-content! when making changes"
|
||||
@@ -362,11 +363,14 @@
|
||||
(ldb/transact! conn (sqlite-create-graph/build-initial-views)))
|
||||
(catch :default _e)))
|
||||
|
||||
(find-missing-addresses db)
|
||||
;; (gc-kvs-table! db)
|
||||
|
||||
(try
|
||||
(when-let [missing-addresses (seq (find-missing-addresses db))]
|
||||
(throw (ex-info "DB missing addresses" {:missing-addresses missing-addresses})))
|
||||
|
||||
(db-migrate/migrate conn search-db)
|
||||
|
||||
(catch :default _e
|
||||
(when db-based?
|
||||
(rebuild-db-from-datoms! conn db import-type)
|
||||
|
||||
Reference in New Issue
Block a user