mirror of
https://github.com/logseq/logseq.git
synced 2026-04-28 16:15:21 +00:00
wip: remove :block/name uniqueness for db based graphs
This PR also remove supports for: 1. merge pages when renaming a page to existing page 2. namespaces such as a/b/c 3. nested page such as [[a [[nested page]]]] Pages merge might be added back depends on RTC, but it should be decoupled from renaming, otherwise it's too complex. Namespaces and nested pages have been contributed some critical bugs that lead data-loss, they're so complex together with page alias, it's just impossible to have a good test coverage and ensure the app is stable, especially when page rename and RTC.
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
[frontend.config :as config]
|
||||
[logseq.graph-parser.db :as gp-db]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.common.util :as common-util]))
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db :as ldb]))
|
||||
|
||||
(defn- build-links
|
||||
[links]
|
||||
@@ -19,9 +20,8 @@
|
||||
links))
|
||||
|
||||
(defn- build-nodes
|
||||
[dark? current-page page-links tags nodes namespaces]
|
||||
(let [parents (set (map last namespaces))
|
||||
current-page (or current-page "")
|
||||
[dark? current-page page-links tags nodes]
|
||||
(let [current-page (or current-page "")
|
||||
pages (set (flatten nodes))]
|
||||
(->>
|
||||
pages
|
||||
@@ -39,13 +39,10 @@
|
||||
color)
|
||||
n (get page-links p 1)
|
||||
size (int (* 8 (max 1.0 (js/Math.cbrt n))))]
|
||||
(cond->
|
||||
{:id p
|
||||
:label p
|
||||
:size size
|
||||
:color color}
|
||||
(contains? parents p)
|
||||
(assoc :parent true))))))))
|
||||
{:id p
|
||||
:label p
|
||||
:size size
|
||||
:color color}))))))
|
||||
|
||||
;; slow
|
||||
(defn- uuid-or-asset?
|
||||
@@ -92,7 +89,6 @@
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(let [relation (db/get-pages-relation repo journal?)
|
||||
tagged-pages (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-tagged-pages repo))
|
||||
namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo))
|
||||
tags (set (map second tagged-pages))
|
||||
full-pages (db/get-all-pages repo)
|
||||
full-pages-map (into {} (map (juxt :block/name identity) full-pages))
|
||||
@@ -110,8 +106,7 @@
|
||||
(not excluded-pages?)
|
||||
(remove (fn [p] (true? (pu/get-block-property-value p :logseq.property/exclude-from-graph-view)))))
|
||||
links (concat (seq relation)
|
||||
(seq tagged-pages)
|
||||
(seq namespaces))
|
||||
(seq tagged-pages))
|
||||
linked (set (flatten links))
|
||||
build-in-pages (->> (if (config/db-based-graph? repo) sqlite-create-graph/built-in-pages-names gp-db/built-in-pages-names)
|
||||
(map string/lower-case)
|
||||
@@ -125,7 +120,7 @@
|
||||
page-links (reduce (fn [m [k v]] (-> (update m k inc)
|
||||
(update v inc))) {} links)
|
||||
links (build-links (remove (fn [[_ to]] (nil? to)) links))
|
||||
nodes (build-nodes dark? (string/lower-case current-page) page-links tags nodes namespaces)]
|
||||
nodes (build-nodes dark? (string/lower-case current-page) page-links tags nodes)]
|
||||
(-> {:nodes (map #(assoc % :block/created-at (get-in full-pages-map [(:id %) :block/created-at])) nodes)
|
||||
:links links
|
||||
:page-name->original-name page-name->original-name}
|
||||
@@ -138,18 +133,16 @@
|
||||
[page theme show-journal]
|
||||
(let [dark? (= "dark" theme)]
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(let [page (util/page-name-sanity-lc page)
|
||||
page-entity (db/entity [:block/name page])
|
||||
(let [page-entity (db/entity (ldb/get-first-page-by-name (db/get-db) page))
|
||||
page-id (:db/id page-entity)
|
||||
tags (if (config/db-based-graph? repo)
|
||||
(set (map #(:block/name (db/entity repo (:db/id %)))
|
||||
(:block/tags page-entity)))
|
||||
(:tags (:block/properties page-entity)))
|
||||
tags (remove #(= page %) tags)
|
||||
ref-pages (db/get-page-referenced-pages repo page)
|
||||
mentioned-pages (db/get-pages-that-mentioned-page repo page show-journal)
|
||||
namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo))
|
||||
ref-pages (db/get-page-referenced-pages repo page-id)
|
||||
mentioned-pages (db/get-pages-that-mentioned-page repo page-id show-journal)
|
||||
links (concat
|
||||
namespaces
|
||||
(map (fn [[p _aliases]]
|
||||
[page p]) ref-pages)
|
||||
(map (fn [[p _aliases]]
|
||||
@@ -163,10 +156,11 @@
|
||||
(set))
|
||||
other-pages-links (mapcat
|
||||
(fn [page]
|
||||
(let [ref-pages (-> (map first (db/get-page-referenced-pages repo page))
|
||||
(let [page-id (ldb/get-first-page-by-name (db/get-db) page)
|
||||
ref-pages (-> (map first (db/get-page-referenced-pages repo page-id))
|
||||
(set)
|
||||
(set/intersection other-pages))
|
||||
mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page show-journal))
|
||||
mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page-id show-journal))
|
||||
(set)
|
||||
(set/intersection other-pages))]
|
||||
(concat
|
||||
@@ -184,7 +178,7 @@
|
||||
tags)
|
||||
(remove nil?)
|
||||
(distinct))
|
||||
nodes (build-nodes dark? page links (set tags) nodes namespaces)
|
||||
nodes (build-nodes dark? page links (set tags) nodes)
|
||||
full-pages (db/get-all-pages repo)
|
||||
all-pages (map common-util/get-page-original-name full-pages)
|
||||
page-name->original-name (zipmap (map :block/name full-pages) all-pages)]
|
||||
@@ -196,40 +190,34 @@
|
||||
(defn build-block-graph
|
||||
"Builds a citation/reference graph for a given block uuid."
|
||||
[block theme]
|
||||
(let [dark? (= "dark" theme)]
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(let [ref-blocks (db/get-block-referenced-blocks block)
|
||||
namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo))
|
||||
links (concat
|
||||
(map (fn [[p _aliases]]
|
||||
[block p]) ref-blocks)
|
||||
namespaces)
|
||||
other-blocks (->> (concat (map first ref-blocks))
|
||||
(remove nil?)
|
||||
(set))
|
||||
other-blocks-links (mapcat
|
||||
(fn [block]
|
||||
(let [ref-blocks (-> (map first (db/get-block-referenced-blocks block))
|
||||
(set)
|
||||
(set/intersection other-blocks))]
|
||||
(concat
|
||||
(map (fn [p] [block p]) ref-blocks))))
|
||||
other-blocks)
|
||||
links (->> (concat links other-blocks-links)
|
||||
(remove nil?)
|
||||
(distinct)
|
||||
(build-links))
|
||||
nodes (->> (concat
|
||||
[block]
|
||||
(map first ref-blocks))
|
||||
(remove nil?)
|
||||
(distinct)
|
||||
(let [dark? (= "dark" theme)
|
||||
ref-blocks (db/get-block-referenced-blocks block)
|
||||
other-blocks (->> (concat (map first ref-blocks))
|
||||
(remove nil?)
|
||||
(set))
|
||||
other-blocks-links (mapcat
|
||||
(fn [block]
|
||||
(let [ref-blocks (-> (map first (db/get-block-referenced-blocks block))
|
||||
(set)
|
||||
(set/intersection other-blocks))]
|
||||
(concat
|
||||
(map (fn [p] [block p]) ref-blocks))))
|
||||
other-blocks)
|
||||
links (->> other-blocks-links
|
||||
(remove nil?)
|
||||
(distinct)
|
||||
(build-links))
|
||||
nodes (->> (concat
|
||||
[block]
|
||||
(map first ref-blocks))
|
||||
(remove nil?)
|
||||
(distinct)
|
||||
;; FIXME: get block tags
|
||||
)
|
||||
nodes (build-nodes dark? block links #{} nodes namespaces)]
|
||||
(normalize-page-name
|
||||
{:nodes nodes
|
||||
:links links})))))
|
||||
)
|
||||
nodes (build-nodes dark? block links #{} nodes)]
|
||||
(normalize-page-name
|
||||
{:nodes nodes
|
||||
:links links})))
|
||||
|
||||
(defn n-hops
|
||||
"Get all nodes that are n hops from nodes (a collection of node ids)"
|
||||
|
||||
Reference in New Issue
Block a user