Skip to content

Commit 75a1312

Browse files
committed
enhance(rtc): add more context when apply-ops return :not-found-target-ops
1 parent cd36c97 commit 75a1312

3 files changed

Lines changed: 46 additions & 17 deletions

File tree

src/main/frontend/worker/rtc/client.cljs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
[frontend.worker.rtc.client-op :as client-op]
1010
[frontend.worker.rtc.const :as rtc-const]
1111
[frontend.worker.rtc.exception :as r.ex]
12+
[frontend.worker.rtc.gen-client-op :as gen-client-op]
1213
[frontend.worker.rtc.log-and-state :as rtc-log-and-state]
1314
[frontend.worker.rtc.malli-schema :as rtc-schema]
1415
[frontend.worker.rtc.remote-update :as r.remote-update]
1516
[frontend.worker.rtc.skeleton :as r.skeleton]
1617
[frontend.worker.rtc.throttle :as r.throttle]
1718
[frontend.worker.rtc.ws :as ws]
1819
[frontend.worker.rtc.ws-util :as ws-util]
20+
[lambdaisland.glogi :as log]
1921
[logseq.db :as ldb]
2022
[logseq.db.frontend.schema :as db-schema]
2123
[missionary.core :as m]
@@ -524,12 +526,25 @@
524526
;; else
525527
(do (rollback repo block-ops-map-coll update-kv-value-ops-map-coll rename-db-ident-ops-map-coll)
526528
(throw (ex-info "Unavailable1" {:remote-ex remote-ex})))))
527-
528-
(do (assert (and (pos? (:t r)) (pos? (:t-query-end r))) r)
529-
(m/?
530-
(r.remote-update/task--apply-remote-update
531-
graph-uuid repo conn date-formatter {:type :remote-update :value r} aes-key add-log-fn))
532-
(add-log-fn :rtc.log/push-local-update {:remote-t (:t r) :remote-t-query-end (:t-query-end r)}))))))))
529+
(if-let [not-found-target-ops (seq (:not-found-target-ops r))]
530+
(do (rollback repo block-ops-map-coll update-kv-value-ops-map-coll rename-db-ident-ops-map-coll)
531+
;; add more ents into ops for remote
532+
(let [ents (mapv
533+
(fn [op]
534+
(let [block-uuid (:block-uuid (second op))]
535+
(assert block-uuid)
536+
(d/entity @conn [:block/uuid block-uuid])))
537+
not-found-target-ops)
538+
extra-ops (gen-client-op/generate-rtc-ops-from-entities+parents ents)]
539+
(log/error :not-found-target-ops not-found-target-ops
540+
:extra-ops extra-ops)
541+
(client-op/add-ops! repo extra-ops)))
542+
543+
(do (assert (and (pos? (:t r)) (pos? (:t-query-end r))) r)
544+
(m/?
545+
(r.remote-update/task--apply-remote-update
546+
graph-uuid repo conn date-formatter {:type :remote-update :value r} aes-key add-log-fn))
547+
(add-log-fn :rtc.log/push-local-update {:remote-t (:t r) :remote-t-query-end (:t-query-end r)})))))))))
533548

534549
(defn new-task--pull-remote-data
535550
[repo conn graph-uuid major-schema-version date-formatter get-ws-create-task aes-key add-log-fn]

src/main/frontend/worker/rtc/gen_client_op.cljs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,28 @@
146146

147147
(defn- generate-rtc-ops-from-entities
148148
[ents]
149-
(let [db (d/entity-db (first ents))
150-
id->same-entity-datoms
151-
(into {}
152-
(map (fn [ent]
153-
(let [e (:db/id ent)
154-
datoms (d/datoms db :eavt e)]
155-
[e datoms])))
156-
ents)
157-
e->a->add?->v->t (update-vals id->same-entity-datoms entity-datoms=>a->add?->v->t)]
158-
(generate-rtc-ops db db (vals id->same-entity-datoms) e->a->add?->v->t)))
149+
(when (seq ents)
150+
(let [db (d/entity-db (first ents))
151+
id->same-entity-datoms
152+
(into {}
153+
(map (fn [ent]
154+
(let [e (:db/id ent)
155+
datoms (d/datoms db :eavt e)]
156+
[e datoms])))
157+
ents)
158+
e->a->add?->v->t (update-vals id->same-entity-datoms entity-datoms=>a->add?->v->t)]
159+
(generate-rtc-ops db db (vals id->same-entity-datoms) e->a->add?->v->t))))
160+
161+
(defn generate-rtc-ops-from-entities+parents
162+
"generate ents and their parents as rtc-ops"
163+
[ents]
164+
(let [ents*
165+
(set
166+
(mapcat
167+
(fn [ent]
168+
(take 20 (take-while some? (iterate :block/parent ent))))
169+
ents))]
170+
(generate-rtc-ops-from-entities ents*)))
159171

160172
(defn generate-rtc-ops-from-property-entities
161173
[property-ents]

src/main/frontend/worker/rtc/malli_schema.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@
187187
[:block/order {:optional true} db-malli-schema/block-order]
188188
[:block/parent {:optional true} :uuid]
189189
[::m/default extra-attr-map-schema]]]]]
190-
[:failed-ops {:optional true}
190+
[:failed-ops {:optional true} ;DEPRECATED
191+
[:maybe [:sequential to-ws-op-schema]]]
192+
[:not-found-target-ops {:optional true}
191193
[:maybe [:sequential to-ws-op-schema]]]])
192194

193195
(def data-from-ws-schema

0 commit comments

Comments
 (0)