fix: checksum failed for empty target block insert

This commit is contained in:
Tienson Qin
2026-04-03 15:59:48 +08:00
parent a1b171a20e
commit 5522b30bcc
3 changed files with 54 additions and 41 deletions

View File

@@ -354,7 +354,7 @@
;; add created-by for new-block
(and (keyword-identical? :block/uuid attr)
(:added datom))
(let [ent (d/entity db-after e)]
(when-let [ent (d/entity db-after e)]
(when-not (:logseq.property/created-by-ref ent)
[:db/add e :logseq.property/created-by-ref created-by-id]))
@@ -364,7 +364,8 @@
(let [origin-title (:block/title (d/entity db-before e))]
(and (some? origin-title)
(string/blank? origin-title))))
[:db/add e :logseq.property/created-by-ref created-by-id])))
(when (d/entity db-after e)
[:db/add e :logseq.property/created-by-ref created-by-id]))))
tx-data)]
(cond->> add-created-by-tx-data
(nil? created-by-ent) (cons created-by-block))))))

View File

@@ -1,32 +1,32 @@
(ns frontend.worker.sync.apply-txs
"Pending tx and remote tx application helpers for db sync."
(:require [clojure.set :as set]
[clojure.string :as string]
[datascript.core :as d]
[frontend.worker.shared-service :as shared-service]
[frontend.worker.state :as worker-state]
[frontend.worker.sync.assets :as sync-assets]
[frontend.worker.sync.auth :as sync-auth]
[frontend.worker.sync.client-op :as client-op]
[frontend.worker.sync.const :as rtc-const]
[frontend.worker.sync.crypt :as sync-crypt]
[frontend.worker.sync.large-title :as sync-large-title]
[frontend.worker.sync.presence :as sync-presence]
[frontend.worker.sync.transport :as sync-transport]
[frontend.worker.undo-redo :as worker-undo-redo]
[lambdaisland.glogi :as log]
[logseq.db :as ldb]
[logseq.db-sync.order :as sync-order]
[logseq.db.common.normalize :as db-normalize]
[logseq.db.frontend.property.type :as db-property-type]
[logseq.db.sqlite.util :as sqlite-util]
[logseq.outliner.core :as outliner-core]
[logseq.outliner.op :as outliner-op]
[logseq.outliner.op.construct :as op-construct]
[logseq.outliner.page :as outliner-page]
[logseq.outliner.property :as outliner-property]
[logseq.outliner.recycle :as outliner-recycle]
[promesa.core :as p]))
(:require
[clojure.set :as set]
[datascript.core :as d]
[frontend.worker.shared-service :as shared-service]
[frontend.worker.state :as worker-state]
[frontend.worker.sync.assets :as sync-assets]
[frontend.worker.sync.auth :as sync-auth]
[frontend.worker.sync.client-op :as client-op]
[frontend.worker.sync.const :as rtc-const]
[frontend.worker.sync.crypt :as sync-crypt]
[frontend.worker.sync.large-title :as sync-large-title]
[frontend.worker.sync.presence :as sync-presence]
[frontend.worker.sync.transport :as sync-transport]
[frontend.worker.undo-redo :as worker-undo-redo]
[lambdaisland.glogi :as log]
[logseq.db :as ldb]
[logseq.db-sync.order :as sync-order]
[logseq.db.common.normalize :as db-normalize]
[logseq.db.frontend.property.type :as db-property-type]
[logseq.db.sqlite.util :as sqlite-util]
[logseq.outliner.core :as outliner-core]
[logseq.outliner.op :as outliner-op]
[logseq.outliner.op.construct :as op-construct]
[logseq.outliner.page :as outliner-page]
[logseq.outliner.property :as outliner-property]
[logseq.outliner.recycle :as outliner-recycle]
[promesa.core :as p]))
(defonce *repo->latest-remote-tx (atom {}))
(defonce *repo->latest-remote-checksum (atom {}))
@@ -601,6 +601,10 @@
(dissoc :db/id)
(assoc :block/created-at now)
(assoc :block/updated-at now))]
(when-not (or (:block/parent block)
(:block/page block))
(throw (ex-info "block doesn't have both parent and page"
block)))
(ldb/transact! conn
[create-block]
{:outliner-op :save-block
@@ -857,6 +861,7 @@
(fn [conn]
(if (= [[:transact nil]] outliner-ops)
(when-let [tx-data (seq (:tx local-tx))]
(prn :debug :transact :tx-data tx-data)
(ldb/transact! conn tx-data {:outliner-op :transact}))
(do
(precreate-missing-save-blocks! conn outliner-ops)
@@ -865,15 +870,8 @@
(catch :default error
(let [drop-log {:tx-id (:tx-id local-tx)
:outliner-ops outliner-ops
:error error}
expected-drop? (or (= "invalid rebase op" (ex-message error))
(string/includes? (or (ex-message error) "")
"doesn't exist yet")
(string/includes? (or (ex-message error) "")
"Nothing found for entity id"))]
(if expected-drop?
(log/debug :db-sync/drop-op-driven-pending-tx drop-log)
(log/warn :db-sync/drop-op-driven-pending-tx drop-log)))
:error error}]
(log/warn :db-sync/drop-op-driven-pending-tx drop-log))
nil))))
(defn- rebase-local-txs!
@@ -990,6 +988,10 @@
[repo {:keys [tx-data db-after db-before] :as tx-report}]
(let [normalized (normalize-tx-data db-after db-before tx-data)
reversed-datoms (reverse-tx-data db-before db-after tx-data)]
;; (prn :debug :enqueue-local-tx :tx-data)
;; (cljs.pprint/pprint tx-data)
;; (prn :debug :enqueue-local-tx :normalized)
;; (cljs.pprint/pprint normalized)
(when (seq normalized)
(persist-local-tx! repo tx-report normalized reversed-datoms)
(when-let [client @worker-state/*db-sync-client]