Skip to content

Commit 4d60c9e

Browse files
committed
Merge branch 'main' into revert-2270-revert-2266-block-perf-by-view
2 parents 808c4a2 + 4bee7f1 commit 4d60c9e

File tree

45 files changed

+1093
-782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1093
-782
lines changed

.carve/ignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
athens.db/help-url
22
athens.db/ego-url
3-
athens.events/shared-blocks-excl-date-pages
43
athens.views.right-sidebar/sidebar-section-heading-style
54
athens.core/init
65
athens.main.core/main

CHANGELOG.md

Lines changed: 184 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Athens",
33
"author": "athensresearch",
4-
"version": "2.1.0-beta.2",
4+
"version": "2.1.0-beta.3",
55
"description": "An open-source knowledege graph for research and notetaking",
66
"repository": {
77
"type": "git",

src/cljc/athens/common_db.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@
642642
txs))
643643

644644

645-
(defn- dissoc-on-match
645+
(defn dissoc-on-match
646646
[m [k f]]
647647
(if (f m)
648648
(dissoc m k)

src/cljc/athens/common_events/bfs.cljc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
"Convert internal representation to the vector of atomic operations that would create it.
129129
:block/save operations are grouped at the end so that any ref'd entities are already created."
130130
[db internal-representation default-position]
131+
(when-not (or (vector? internal-representation)
132+
(list? internal-representation))
133+
(throw "Internal representation must be a vector"))
131134
(->> internal-representation
132135
add-missing-block-uids
133136
enhance-internal-representation

src/cljc/athens/common_events/graph/ops.cljc

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,34 +310,69 @@
310310
[removed-links added-links]))
311311

312312

313+
(defn throw-unknown-k
314+
[k]
315+
(throw (str "Key " k " must be either string or ::first/::last.")))
316+
317+
313318
(defn- new-prop
314-
[db [a v :as uid-or-eid] prop-uid k]
319+
[db [a v :as uid-or-eid] next-uid k]
315320
(let [uid? (-> uid-or-eid vector? not)
316321
uid (if uid?
317322
uid-or-eid
318323
(common-db/get-block-uid db uid-or-eid))
319324
title (or (common-db/get-page-title db uid)
320325
(and (= a :node/title) v))
321-
position (merge {:relation {:page/title k}}
326+
;; here too
327+
position (merge {:relation (cond
328+
(= ::first k) :first
329+
(= ::last k) :last
330+
(string? k) {:page/title k}
331+
:else (throw-unknown-k k))}
322332
(if title
323333
{:page/title title}
324334
{:block/uid uid}))]
325-
(build-block-new-op db prop-uid position)))
335+
(build-block-new-op db next-uid position)))
326336

327337

328-
(defn build-property-path
338+
(defn build-path
339+
"Return uid at ks path and operations to create path, if needed, as [uid ops].
340+
uid can be a string or a datascript eid.
341+
ks can be properties names as strings, or ::first/::last for children."
329342
([db uid ks]
330-
(build-property-path db uid ks []))
343+
(build-path db uid ks []))
331344
([db uid-or-eid [k & ks] ops]
332345
(if-not k
333346
[uid-or-eid ops]
334347
(let [uid? (-> uid-or-eid vector? not)
335348
block (common-db/get-block db (if uid?
336349
[:block/uid uid-or-eid]
337350
uid-or-eid))
338-
prop-block (-> block :block/properties (get k))
339-
prop-uid (or (:block/uid prop-block)
351+
next-block (cond
352+
(= ::first k) (-> block :block/children first)
353+
(= ::last k) (-> block :block/children last)
354+
(string? k) (-> block :block/properties (get k))
355+
:else (throw-unknown-k k))
356+
next-uid (or (:block/uid next-block)
340357
(common.utils/gen-block-uid))
341358
ops' (cond-> ops
342-
(not prop-block) (conj (new-prop db uid-or-eid prop-uid k)))]
343-
(recur db prop-uid ks ops')))))
359+
(not next-block) (conj (new-prop db uid-or-eid next-uid k)))]
360+
(recur db next-uid ks ops')))))
361+
362+
363+
(defn get-path
364+
"Return uid at ks path."
365+
[db uid-or-eid [k & ks]]
366+
(if-not (and uid-or-eid k)
367+
uid-or-eid
368+
(let [uid? (-> uid-or-eid vector? not)
369+
block (common-db/get-block db (if uid?
370+
[:block/uid uid-or-eid]
371+
uid-or-eid))
372+
next-block (cond
373+
(= ::first k) (-> block :block/children first)
374+
(= ::last k) (-> block :block/children last)
375+
(string? k) (-> block :block/properties (get k))
376+
:else (throw-unknown-k k))
377+
next-uid (:block/uid next-block)]
378+
(recur db next-uid ks))))

src/cljc/athens/common_events/resolver/atomic.cljc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
1818

1919
(defmethod resolve-atomic-op-to-tx :block/new
2020
[db {:op/keys [args]} event-ref]
21-
(let [{:block/keys [uid position]} args
22-
new-block {:block/uid uid
23-
:block/string ""
24-
:block/open true
25-
:block/create event-ref
26-
:block/edits event-ref}
27-
position-tx (condp = (position/position-type position)
28-
:child (position/add-child db uid position event-ref)
29-
:property (position/add-property db uid position event-ref))
30-
tx-data (into [new-block] position-tx)]
31-
tx-data))
21+
(let [{:block/keys [uid position]} args]
22+
(if (common-db/block-exists? db [:block/uid uid])
23+
;; Treast :block/new on an existing block as a :block/move instead.
24+
(resolve-atomic-op-to-tx db {:op/type :block/move
25+
:op/args args}
26+
event-ref)
27+
(let [new-block {:block/uid uid
28+
:block/string ""
29+
:block/open true
30+
:block/create event-ref
31+
:block/edits event-ref}
32+
position-tx (condp = (position/position-type position)
33+
:child (position/add-child db uid position event-ref)
34+
:property (position/add-property db uid position event-ref))
35+
tx-data (into [new-block] position-tx)]
36+
tx-data))))
3237

3338

3439
;; This is Atomic Graph Op, there is also composite version of it
@@ -78,8 +83,8 @@
7883
(if same-parent?
7984
(position/move-child-within
8085
db old-parent-uid uid position event-ref)
81-
(position/move-child-between
82-
db old-parent-uid new-parent-uid uid position event-ref))
86+
(concat (position/remove-child db uid old-parent-uid event-ref)
87+
(position/add-child db uid position event-ref)))
8388

8489
[:child :property]
8590
(concat

src/cljc/athens/common_events/resolver/order.cljc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@
5353
:else v)))
5454

5555

56-
(defn move-between
57-
"Move x from origin to destination, to a position defined by relation to target.
58-
See athens.common-events.graph.schema for position values.
59-
Returns [modified-origin modified-destination]."
60-
[origin destination x relation target]
61-
[(remove origin x) (insert destination x relation target)])
62-
63-
6456
(defn move-within
6557
"Move x within v, to a position defined by relation to target.
6658
See athens.common-events.graph.schema for position values.

src/cljc/athens/common_events/resolver/position.cljc

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,6 @@
4747
(concat reorder edit)))
4848

4949

50-
(defn move-child-between
51-
[db old-parent-uid new-parent-uid uid position event-ref]
52-
(let [{:keys [relation]} position
53-
[ref-uid] (common-db/position->uid+parent db position)
54-
origin-children (common-db/get-children-uids db [:block/uid old-parent-uid])
55-
destination-children (common-db/get-children-uids db [:block/uid new-parent-uid])
56-
[origin-children'
57-
destination-children'] (order/move-between origin-children destination-children uid relation ref-uid)
58-
reorder-origin (order/reorder origin-children origin-children' order/block-map-fn)
59-
reorder-destination (order/reorder destination-children destination-children' order/block-map-fn)
60-
update-parent [[:db/retract [:block/uid old-parent-uid] :block/children [:block/uid uid]]
61-
{:block/uid old-parent-uid
62-
:block/edits event-ref}
63-
{:block/uid new-parent-uid
64-
:block/children [{:block/uid uid}]
65-
:block/edits event-ref}]]
66-
(concat reorder-origin reorder-destination update-parent)))
67-
68-
6950
(defn add-property
7051
"Add uid as property under position. Transaction will fail if a property for position already exists."
7152
[db uid position event-ref]

src/cljs/athens/db.cljs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -252,43 +252,6 @@
252252
(-> (d/datoms @dsdb :eavt e a) first :v))
253253

254254

255-
(def rules
256-
'[[(after ?p ?at ?ch ?o)
257-
[?p :block/children ?ch]
258-
[?ch :block/order ?o]
259-
[(> ?o ?at)]]
260-
[(between ?p ?lower-bound ?upper-bound ?ch ?o)
261-
[?p :block/children ?ch]
262-
[?ch :block/order ?o]
263-
[(> ?o ?lower-bound)]
264-
[(< ?o ?upper-bound)]]
265-
[(inc-after ?p ?at ?ch ?new-o)
266-
(after ?p ?at ?ch ?o)
267-
[(inc ?o) ?new-o]]
268-
[(dec-after ?p ?at ?ch ?new-o)
269-
(after ?p ?at ?ch ?o)
270-
[(dec ?o) ?new-o]]
271-
[(plus-after ?p ?at ?ch ?new-o ?x)
272-
(after ?p ?at ?ch ?o)
273-
[(+ ?o ?x) ?new-o]]
274-
[(minus-after ?p ?at ?ch ?new-o ?x)
275-
(after ?p ?at ?ch ?o)
276-
[(- ?o ?x) ?new-o]]
277-
[(siblings ?uid ?sib-e)
278-
[?e :block/uid ?uid]
279-
[?p :block/children ?e]
280-
[?p :block/children ?sib-e]]])
281-
282-
283-
(defn inc-after
284-
[eid order]
285-
(->> (d/q '[:find ?ch ?new-o
286-
:keys db/id block/order
287-
:in $ % ?p ?at
288-
:where (inc-after ?p ?at ?ch ?new-o)]
289-
@dsdb rules eid order)))
290-
291-
292255
(defn uid-and-embed-id
293256
[uid]
294257
(or (some->> uid
@@ -305,32 +268,6 @@
305268
block))
306269

307270

308-
(def block-document-pull-vector
309-
'[:db/id :block/uid :block/string :block/open :block/order {:block/children ...} :block/refs :block/_refs])
310-
311-
312-
(def node-document-pull-vector
313-
(-> block-document-pull-vector
314-
(conj :node/title :page/sidebar)))
315-
316-
317-
(def roam-node-document-pull-vector
318-
'[:node/title :block/uid :block/string :block/open :block/order {:block/children ...}])
319-
320-
321-
(defntrace get-node-document
322-
[id db]
323-
(when (d/entity db id)
324-
(->> (d/pull db node-document-pull-vector id)
325-
sort-block-children)))
326-
327-
328-
(defntrace get-roam-node-document
329-
[id db]
330-
(->> (d/pull db roam-node-document-pull-vector id)
331-
sort-block-children))
332-
333-
334271
(defntrace shape-parent-query
335272
"Normalize path from deeply nested block to root node."
336273
[pull-results]

0 commit comments

Comments
 (0)