Skip to content

Commit

Permalink
Merge branch 'main' into revert-2270-revert-2266-block-perf-by-view
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Aug 10, 2022
2 parents ec1fa16 + 5287f2b commit acf1c19
Show file tree
Hide file tree
Showing 22 changed files with 1,503 additions and 1,176 deletions.
4 changes: 2 additions & 2 deletions .carve/ignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ athens.common-events.graph.schema/explain-atomic-op
athens.style/unzoom
athens.self-hosted.fluree.test-helpers/query
athens.views.jetsam/jetsam-component
athens.views.task.core/new-task
athens.views.task.core/update-task-properties
athens.types.tasks.view/new-task
athens.types.tasks.view/update-task-properties
10 changes: 10 additions & 0 deletions src/cljc/athens/common_db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,16 @@
:block/properties))


(defn get-entity-type
"Returns the value of eids `:entity/type` prop, if any."
[db eid]
(->> (d/entity db eid)
:block/_property-of
(some (fn [e]
(when (-> e :block/key :node/title (= ":entity/type"))
(:block/string e))))))


(defn get-block-uid
"Finds block `:block/uid` by eid."
[db eid]
Expand Down
20 changes: 20 additions & 0 deletions src/cljc/athens/common_events/bfs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[athens.common-events.graph.composite :as composite]
[athens.common-events.graph.ops :as graph-ops]
[athens.common-events.resolver.atomic :as atomic-resolver]
[athens.common.utils :as common.utils]
[clojure.string :as string]
[clojure.walk :as walk]))

Expand Down Expand Up @@ -105,11 +106,30 @@
(concat [] not-save save)))


(defn add-missing-block-uids
[internal-representation]
(walk/postwalk
(fn [x]
(if (and (map? x)
;; looks like a block
(or (:block/string x)
(:block/properties x)
(:block/children x)
(:block/open? x))
;; but doesn't have uid
(not (:block/uid x)))
;; add it
(assoc x :block/uid (common.utils/gen-block-uid))
x))
internal-representation))


(defn internal-representation->atomic-ops
"Convert internal representation to the vector of atomic operations that would create it.
:block/save operations are grouped at the end so that any ref'd entities are already created."
[db internal-representation default-position]
(->> internal-representation
add-missing-block-uids
enhance-internal-representation
(mapcat (partial tree-seq common-db/has-descendants? common-db/descendants))
(map (partial enhanced-internal-representation->atomic-ops db default-position))
Expand Down
32 changes: 22 additions & 10 deletions src/cljc/athens/common_events/graph/ops.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,17 @@
(defn build-block-split-op
"Creates `:block/split` composite op, taking into account context.
If old-block has children, pass them on to new-block.
If old-block is open or closed, pass that state on to new-block."
If old-block is open or closed, pass that state on to new-block.
Ignores both behaviours above if old-block is a property."
[db {:keys [old-block-uid new-block-uid
string index relation]}]
(let [save-block-op (build-block-save-op db old-block-uid (subs string 0 index))
new-block-op (atomic/make-block-new-op new-block-uid {:block/uid old-block-uid
:relation relation})
new-block-save-op (build-block-save-op db new-block-uid (subs string index))
{:block/keys [open]} (common-db/get-block db [:block/uid old-block-uid])
children (common-db/get-children-uids db [:block/uid old-block-uid])
{:block/keys [open key]} (common-db/get-block db [:block/uid old-block-uid])
children (when-not key
(common-db/get-children-uids db [:block/uid old-block-uid]))
children? (seq children)
move-children-op (when children?
(block-move-chain db new-block-uid children :first))
Expand Down Expand Up @@ -309,24 +311,34 @@


(defn- new-prop
[db uid prop-uid k]
(let [position (merge {:relation {:page/title k}}
(if-let [title (common-db/get-page-title db uid)]
[db [a v :as uid-or-eid] prop-uid k]
(let [uid? (-> uid-or-eid vector? not)
uid (if uid?
uid-or-eid
(common-db/get-block-uid db uid-or-eid))
title (or (common-db/get-page-title db uid)
(and (= a :node/title) v))
position (merge {:relation {:page/title k}}
(if title
{:page/title title}
{:block/uid uid}))]
(println position)
(build-block-new-op db prop-uid position)))


(defn build-property-path
([db uid ks]
(build-property-path db uid ks []))
([db uid [k & ks] ops]
([db uid-or-eid [k & ks] ops]
(if-not k
[uid ops]
(let [block (common-db/get-block db [:block/uid uid])
[uid-or-eid ops]
(let [uid? (-> uid-or-eid vector? not)
block (common-db/get-block db (if uid?
[:block/uid uid-or-eid]
uid-or-eid))
prop-block (-> block :block/properties (get k))
prop-uid (or (:block/uid prop-block)
(common.utils/gen-block-uid))
ops' (cond-> ops
(not prop-block) (conj (new-prop db uid prop-uid k)))]
(not prop-block) (conj (new-prop db uid-or-eid prop-uid k)))]
(recur db prop-uid ks ops')))))
25 changes: 14 additions & 11 deletions src/cljs/athens/components.cljs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(ns athens.components
(:require
["@chakra-ui/react" :refer [Checkbox Button]]
[athens.db :as db]
[athens.parse-renderer :refer [component]]
[athens.views.blocks.core :as blocks]
[athens.views.blocks.types :as types]
[athens.views.blocks.types.dispatcher :as block-type-dispatcher]
[clojure.string :as str]
[re-frame.core :as rf]))
["@chakra-ui/react" :refer [Checkbox Button]]
[athens.db :as db]
[athens.parse-renderer :refer [component]]
[athens.reactive :as reactive]
[athens.types.core :as types]
[athens.types.dispatcher :as block-type-dispatcher]
[athens.views.blocks.core :as blocks]
[clojure.string :as str]
[re-frame.core :as rf]))


(defn todo-on-click
Expand Down Expand Up @@ -81,9 +82,11 @@
(let [block-uid (last (re-find #"\(\((.+)\)\)" content))
block-eid (db/e-by-av :block/uid block-uid)]
(if block-eid
(let [;; TODO: make real block type discovery
block-type nil
renderer (block-type-dispatcher/block-type->protocol block-type {})]
(let [block-type (reactive/reactive-get-entity-type [:block/uid block-uid])
ff @(rf/subscribe [:feature-flags])
renderer-k (block-type-dispatcher/block-type->protocol-k block-type ff)
renderer (block-type-dispatcher/block-type->protocol renderer-k {})]
^{:key renderer-k}
[types/transclusion-view renderer blocks/block-el block-uid {} :embed])
;; roam actually hides the brackets around [[embed]]
[:span "{{" content "}}"])))
Expand Down
12 changes: 1 addition & 11 deletions src/cljs/athens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,10 @@
(d/datoms @dsdb :aevt :node/title))))))


(defn get-entity-type
"Returns the value of eids `:entity/type` prop, if any"
[db eid]
(->> (d/entity db eid)
:block/_property-of
(some (fn [e]
(when (-> e :block/key :node/title (= ":entity/type"))
(:block/string e))))))


(defn get-root-parent-node-from-block
[db {:keys [block/uid] :as block}]
(cond
(= "[[athens/comment]]" (get-entity-type db [:block/uid uid]))
(= "[[athens/comment]]" (common-db/get-entity-type db [:block/uid uid]))
(let [commented-block (-> block
;; comments are a child of :comments/threads
:block/_children first
Expand Down
31 changes: 17 additions & 14 deletions src/cljs/athens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,9 +1341,12 @@
{:keys [value start]} d-key-down
event (cond
(:block/key block)
[:enter/open-block-add-child {:block block
:new-uid new-uid
:embed-id embed-id}]
[:enter/split-block {:uid uid
:value value
:index start
:new-uid new-uid
:embed-id embed-id
:relation :first}]

(and (:block/open block)
has-children?
Expand Down Expand Up @@ -1805,16 +1808,16 @@

;; Works like clojure's update-in.
;; Calls (f db uid), where uid is the existing block uid, or a uid that will be created in ks property path.
;; (f db uid) should return a seq of operations to perform. If no operations are return, nothing is transacted.
;; (f db uid) should return a seq of operations to perform. If no operations are returned, nothing is transacted.
(reg-event-fx
:properties/update-in
(fn [_ [_ id ks f]]
(log/debug ":properties/update-in args" id ks)
(let [db @db/dsdb
uid (common-db/get-block-uid db id)
[prop-uid path-ops] (graph-ops/build-property-path db uid ks)
f-ops (f db prop-uid)]
(when (seq f-ops)
{:fx [[:dispatch-n [[:resolve-transact-forward (->> (into path-ops f-ops)
(composite-ops/make-consequence-op {:op/type :properties/update})
common-events/build-atomic-event)]]]]}))))
(fn [_ [_ eid ks f]]
(log/debug ":properties/update-in args" eid ks)
(when (seq ks)
(let [db @db/dsdb
[prop-uid path-ops] (graph-ops/build-property-path db eid ks)
f-ops (f db prop-uid)]
(when (seq f-ops)
{:fx [[:dispatch-n [[:resolve-transact-forward (->> (into path-ops f-ops)
(composite-ops/make-consequence-op {:op/type :properties/update})
common-events/build-atomic-event)]]]]})))))
34 changes: 18 additions & 16 deletions src/cljs/athens/parse_renderer.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
^:cljstyle/ignore
(ns athens.parse-renderer
(:require
["@chakra-ui/react" :refer [Link Button Text Box]]
["katex" :as katex]
["@chakra-ui/react" :refer [Link Button Text Box]]
["katex" :as katex]
["katex/dist/contrib/mhchem"]
[athens.config :as config]
[athens.parser.impl :as parser-impl]
[athens.reactive :as reactive]
[athens.router :as router]
[athens.views.blocks.types :as types]
[athens.views.blocks.types.dispatcher :as block-type-dispatcher]
[clojure.string :as str]
[instaparse.core :as insta]
[re-frame.core :as rf]
[reagent.core :as r]))
[athens.config :as config]
[athens.parser.impl :as parser-impl]
[athens.reactive :as reactive]
[athens.router :as router]
[athens.types.core :as types]
[athens.types.dispatcher :as block-type-dispatcher]
[clojure.string :as str]
[instaparse.core :as insta]
[re-frame.core :as rf]
[reagent.core :as r]))


(declare parse-and-render)
Expand Down Expand Up @@ -202,9 +202,12 @@
[:span {:class "contents"} title-coll]])
:block-ref (fn [{_from :from :as attr} ref-uid]
(let [block (reactive/get-reactive-block-or-page-by-uid ref-uid)
block-type nil ; TODO: make real block type discovery
renderer (block-type-dispatcher/block-type->protocol block-type {})]
(types/inline-ref-view renderer block attr ref-uid uid {} true)))
block-type (reactive/reactive-get-entity-type [:block/uid ref-uid])
ff @(rf/subscribe [:feature-flags])
renderer-k (block-type-dispatcher/block-type->protocol-k block-type ff)
renderer (block-type-dispatcher/block-type->protocol renderer-k {})]
^{:key renderer-k}
[types/inline-ref-view renderer block attr ref-uid uid {} true]))
:url-image (fn [{url :src alt :alt}]
[:> Box {:class "url-image"
:as "img"
Expand Down Expand Up @@ -338,4 +341,3 @@
(js/console.log "view creation:" vt-total)
(js/console.groupEnd))
view))))

10 changes: 10 additions & 0 deletions src/cljs/athens/reactive.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@
@(p/pull db/dsdb '[:node/title :block/string :db/id] [:block/uid uid]))


(defntrace reactive-get-entity-type
"Reactive version of athens.common-db/get-entity-type."
[eid]
(->> @(p/pull db/dsdb '[{:block/_property-of [:block/string {:block/key [:node/title]}]}] eid)
:block/_property-of
(some (fn [e]
(when (-> e :block/key :node/title (= ":entity/type"))
(:block/string e))))))


(comment
;; Print what ratoms are active.
(-> (ratoms) utils/spy))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns athens.views.blocks.types
(ns athens.types.core
"Athens Block/Entity Types")


Expand All @@ -10,7 +10,7 @@
"Render Block/Entity Type as inline reference")

(outline-view
[this block-data block-el callbacks]
[this block-data callbacks]
"Render Block/Entity Type as outline representation")

(supported-transclusion-scopes
Expand Down
Loading

0 comments on commit acf1c19

Please sign in to comment.