Skip to content

Commit 7d71962

Browse files
committed
refactor: prefer conn than repo for outliner core and rtc update
1 parent f6188b6 commit 7d71962

23 files changed

Lines changed: 231 additions & 415 deletions

File tree

deps/outliner/src/logseq/outliner/core.cljs

Lines changed: 73 additions & 94 deletions
Large diffs are not rendered by default.

deps/outliner/src/logseq/outliner/op.cljs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
(reset! *result {:error (str "Unexpected Import EDN error: " (pr-str (ex-message e)))}))))))
170170

171171
(defn ^:large-vars/cleanup-todo apply-ops!
172-
[repo conn ops date-formatter opts]
172+
[conn ops opts]
173173
(assert (ops-validator ops) ops)
174174
(let [opts' (assoc opts
175175
:transact-opts {:conn conn}
@@ -181,37 +181,37 @@
181181
(case op
182182
;; blocks
183183
:save-block
184-
(apply outliner-core/save-block! repo conn date-formatter args)
184+
(apply outliner-core/save-block! conn args)
185185

186186
:insert-blocks
187187
(let [[blocks target-block-id opts] args]
188188
(when-let [target-block (d/entity @conn target-block-id)]
189-
(let [result (outliner-core/insert-blocks! repo conn blocks target-block opts)]
189+
(let [result (outliner-core/insert-blocks! conn blocks target-block opts)]
190190
(reset! *result result))))
191191

192192
:delete-blocks
193193
(let [[block-ids opts] args
194194
blocks (keep #(d/entity @conn %) block-ids)]
195-
(outliner-core/delete-blocks! repo conn date-formatter blocks (merge opts opts')))
195+
(outliner-core/delete-blocks! conn blocks (merge opts opts')))
196196

197197
:move-blocks
198198
(let [[block-ids target-block-id opts] args
199199
blocks (keep #(d/entity @conn %) block-ids)
200200
target-block (d/entity @conn target-block-id)]
201201
(when (and target-block (seq blocks))
202-
(outliner-core/move-blocks! repo conn blocks target-block opts)))
202+
(outliner-core/move-blocks! conn blocks target-block opts)))
203203

204204
:move-blocks-up-down
205205
(let [[block-ids up?] args
206206
blocks (keep #(d/entity @conn %) block-ids)]
207207
(when (seq blocks)
208-
(outliner-core/move-blocks-up-down! repo conn blocks up?)))
208+
(outliner-core/move-blocks-up-down! conn blocks up?)))
209209

210210
:indent-outdent-blocks
211211
(let [[block-ids indent? opts] args
212212
blocks (keep #(d/entity @conn %) block-ids)]
213213
(when (seq blocks)
214-
(outliner-core/indent-outdent-blocks! repo conn blocks indent? opts)))
214+
(outliner-core/indent-outdent-blocks! conn blocks indent? opts)))
215215

216216
;; properties
217217
:upsert-property
@@ -260,6 +260,6 @@
260260
(apply ldb/transact! conn args)
261261

262262
(when-let [handler (get @*op-handlers op)]
263-
(reset! *result (handler repo conn args))))))
263+
(reset! *result (handler conn args))))))
264264

265265
@*result))

deps/outliner/src/logseq/outliner/tree.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[logseq.db.common.property-util :as db-property-util]))
77

88
(defprotocol INode
9-
(-save [this *txs-state conn repo date-formatter opts])
9+
(-save [this *txs-state conn opts])
1010
(-del [this *txs-state db]))
1111

1212
(defn- blocks->vec-tree-aux

deps/outliner/test/logseq/outliner/core_test.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
property-value (:user.property/default (db-test/find-block-by-content @conn "b1"))
1414
_ (assert (:db/id property-value))
1515
block (db-test/find-block-by-content @conn "b1")]
16-
(outliner-core/delete-blocks! nil conn nil [block] {})
16+
(outliner-core/delete-blocks! conn [block] {})
1717
(is (nil? (db-test/find-block-by-content @conn "b1")))
1818
(is (nil? (db-test/find-block-by-content @conn "test block"))))))
1919

@@ -32,7 +32,7 @@
3232
:block/parent (:db/id page1)}])
3333
b3 (db-test/find-block-by-content @conn "b3")
3434
b4 (db-test/find-block-by-content @conn "b4")]
35-
(outliner-core/delete-blocks! nil conn nil [b3 b4 page2] {})
35+
(outliner-core/delete-blocks! conn [b3 b4 page2] {})
3636
(is (some? (db-test/find-block-by-content @conn "b3")))
3737
(is (some? (db-test/find-block-by-content @conn "b4")))
3838
(let [page2' (ldb/get-page @conn "page2")]

public/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,5 @@
6262
<script defer src="/static/js/tabler-icons-react.min.js"></script>
6363
<script defer src="/static/js/tabler.ext.js"></script>
6464
<script defer src="/static/js/code-editor.js"></script>
65-
<script defer src="/static/js/tldraw.js"></script>
66-
<script defer src="/static/js/excalidraw.js"></script>
6765
</body>
6866
</html>

src/main/frontend/db/transact.cljs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
[conn ops opts]
3333
(when (seq ops)
3434
(if util/node-test?
35-
(outliner-op/apply-ops! (state/get-current-repo)
36-
conn
37-
ops
38-
(state/get-date-formatter)
39-
opts)
35+
(outliner-op/apply-ops! conn ops opts)
4036
(let [opts' (assoc opts
4137
:client-id (:client-id @state/state)
4238
:local-tx? true)

src/main/frontend/worker/db_worker.cljs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@
606606
(try
607607
(worker-util/profile
608608
"apply outliner ops"
609-
(outliner-op/apply-ops! repo conn ops (worker-state/get-date-formatter repo) opts))
609+
(outliner-op/apply-ops! conn ops opts))
610610
(catch :default e
611611
(let [data (ex-data e)
612612
{:keys [type payload]} (when (map? data) data)]
@@ -783,30 +783,29 @@
783783
(throw (ex-info "Rename page is a file graph only operation" {})))
784784

785785
(defn- delete-page!
786-
[repo conn page-uuid]
786+
[conn page-uuid]
787787
(let [error-handler (fn [{:keys [msg]}]
788788
(worker-util/post-message :notification
789789
[[:div [:p msg]] :error]))]
790-
(worker-page/delete! repo conn page-uuid {:error-handler error-handler})))
790+
(worker-page/delete! conn page-uuid {:error-handler error-handler})))
791791

792792
(defn- create-page!
793-
[repo conn title options]
794-
(let [config (worker-state/get-config repo)]
795-
(try
796-
(worker-page/create! repo conn config title options)
797-
(catch :default e
798-
(js/console.error e)
799-
(throw e)))))
793+
[conn title options]
794+
(try
795+
(worker-page/create! conn title options)
796+
(catch :default e
797+
(js/console.error e)
798+
(throw e))))
800799

801800
(defn- outliner-register-op-handlers!
802801
[]
803802
(outliner-op/register-op-handlers!
804-
{:create-page (fn [repo conn [title options]]
805-
(create-page! repo conn title options))
803+
{:create-page (fn [conn [title options]]
804+
(create-page! conn title options))
806805
:rename-page (fn [& _]
807806
(rename-page!))
808-
:delete-page (fn [repo conn [page-uuid]]
809-
(delete-page! repo conn page-uuid))}))
807+
:delete-page (fn [conn [page-uuid]]
808+
(delete-page! conn page-uuid))}))
810809

811810
(defn- on-become-master
812811
[repo start-opts]

src/main/frontend/worker/handler/page.cljs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
(ns frontend.worker.handler.page
22
"Page operations"
3-
(:require [logseq.common.config :as common-config]
4-
[logseq.common.util :as common-util]
3+
(:require [logseq.common.util :as common-util]
54
[logseq.db :as ldb]
65
[logseq.graph-parser.block :as gp-block]
76
[logseq.outliner.page :as outliner-page]))
87

98
(defn rtc-create-page!
10-
[conn config title {:keys [uuid old-db-id]}]
9+
[conn title date-formatter {:keys [uuid old-db-id]}]
1110
(assert (uuid? uuid) (str "rtc-create-page! `uuid` is not a uuid " uuid))
12-
(let [date-formatter (common-config/get-date-formatter config)
13-
title (outliner-page/sanitize-title title)
11+
(let [title (outliner-page/sanitize-title title)
1412
page-name (common-util/page-name-sanity-lc title)
1513
page (cond-> (gp-block/page-name->map title @conn true date-formatter
1614
{:page-uuid uuid
@@ -32,11 +30,11 @@
3230
* :persist-op? - when true, add an update-page op
3331
* :properties - properties to add to the page
3432
TODO: Add other options"
35-
[repo conn config title & {:as options}]
33+
[conn title & {:as options}]
3634
(outliner-page/create! conn title options))
3735

3836
(defn delete!
3937
"Deletes a page. Returns true if able to delete page. If unable to delete,
4038
calls error-handler fn and returns false"
41-
[repo conn page-uuid & {:as options}]
39+
[conn page-uuid & {:as options}]
4240
(outliner-page/delete! conn page-uuid options))

src/main/frontend/worker/pipeline.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@
9696
(:block/uuid e)))))))]
9797
blocks))))]
9898
(when (seq template-blocks)
99-
;; FIXME: outliner core apis shouldn't use `repo`
10099
(let [result (outliner-core/insert-blocks
101-
repo db template-blocks object
100+
db template-blocks object
102101
{:sibling? false
103102
:keep-uuid? journal-template?
104103
:outliner-op :insert-template-blocks})]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
(do (assert (and (pos? (:t apply-ops-resp)) (pos? (:t-query-end apply-ops-resp))) apply-ops-resp)
4040
(m/?
4141
(r.remote-update/task--apply-remote-update
42-
graph-uuid repo conn date-formatter {:type :remote-update :value apply-ops-resp} aes-key add-log-fn))))))
42+
graph-uuid repo conn {:type :remote-update :value apply-ops-resp} aes-key add-log-fn))))))
4343

4444
(defn- new-task--init-request
4545
[get-ws-create-task graph-uuid major-schema-version repo conn *last-calibrate-t *server-schema-version add-log-fn]
@@ -543,7 +543,7 @@
543543
(do (assert (and (pos? (:t r)) (pos? (:t-query-end r))) r)
544544
(m/?
545545
(r.remote-update/task--apply-remote-update
546-
graph-uuid repo conn date-formatter {:type :remote-update :value r} aes-key add-log-fn))
546+
graph-uuid repo conn {:type :remote-update :value r} aes-key add-log-fn))
547547
(add-log-fn :rtc.log/push-local-update {:remote-t (:t r) :remote-t-query-end (:t-query-end r)})))))))))
548548

549549
(defn new-task--pull-remote-data

0 commit comments

Comments
 (0)