mirror of
https://github.com/logseq/logseq.git
synced 2026-05-04 19:06: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:
11
deps/graph-parser/src/logseq/graph_parser.cljs
vendored
11
deps/graph-parser/src/logseq/graph_parser.cljs
vendored
@@ -23,12 +23,11 @@
|
||||
[db file-path]
|
||||
(ffirst
|
||||
(d/q
|
||||
'[:find ?page-name
|
||||
'[:find ?page
|
||||
:in $ ?path
|
||||
:where
|
||||
[?file :file/path ?path]
|
||||
[?page :block/file ?file]
|
||||
[?page :block/original-name ?page-name]]
|
||||
[?page :block/file ?file]]
|
||||
db
|
||||
file-path)))
|
||||
|
||||
@@ -50,9 +49,9 @@
|
||||
UUIDs."
|
||||
[db file-page file-path retain-uuid-blocks]
|
||||
(let [existing-file-page (get-file-page db file-path)
|
||||
pages-to-clear (distinct (filter some? [existing-file-page (:block/name file-page)]))
|
||||
blocks (mapcat (fn [page]
|
||||
(ldb/get-page-blocks db page {:pull-keys [:db/id :block/uuid]}))
|
||||
pages-to-clear (distinct (filter some? [existing-file-page (:db/id file-page)]))
|
||||
blocks (mapcat (fn [page-id]
|
||||
(ldb/get-page-blocks db page-id {:pull-keys [:db/id :block/uuid]}))
|
||||
pages-to-clear)
|
||||
retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
|
||||
(retract-blocks-tx (distinct blocks) retain-uuids)))
|
||||
|
||||
@@ -292,8 +292,6 @@
|
||||
(and original-page-name (string? original-page-name))
|
||||
(let [original-page-name (common-util/remove-boundary-slashes original-page-name)
|
||||
[original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)
|
||||
namespace? (and (not (boolean (text/get-nested-page-name original-page-name)))
|
||||
(text/namespace-page? original-page-name))
|
||||
page-entity (some-> db (d/entity [:block/name page-name]))
|
||||
original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
|
||||
(merge
|
||||
@@ -305,10 +303,6 @@
|
||||
(uuid? with-id?) with-id?)
|
||||
(d/squuid))]
|
||||
{:block/uuid new-uuid}))
|
||||
(when namespace?
|
||||
(let [namespace (first (common-util/split-last "/" original-page-name))]
|
||||
(when-not (string/blank? namespace)
|
||||
{:block/namespace {:block/name (common-util/page-name-sanity-lc namespace)}})))
|
||||
(when (and with-timestamp? (not page-entity)) ;; Only assign timestamp on creating new entity
|
||||
(let [current-ms (common-util/time-ms)]
|
||||
{:block/created-at current-ms
|
||||
@@ -353,19 +347,7 @@
|
||||
(let [*name->id (atom {})
|
||||
ref->map-fn (fn [*col _tag?]
|
||||
(let [col (remove string/blank? @*col)
|
||||
children-pages (->> (mapcat (fn [p]
|
||||
(let [p (if (map? p)
|
||||
(:block/original-name p)
|
||||
p)]
|
||||
(when (string? p)
|
||||
(let [p (or (text/get-nested-page-name p) p)]
|
||||
(when (text/namespace-page? p)
|
||||
(common-util/split-namespace-pages p))))))
|
||||
col)
|
||||
(remove string/blank?)
|
||||
(distinct))
|
||||
col (->> (distinct (concat col children-pages))
|
||||
(remove nil?))]
|
||||
col (distinct col)]
|
||||
(map
|
||||
(fn [item]
|
||||
(let [macro? (and (map? item)
|
||||
|
||||
@@ -603,7 +603,7 @@
|
||||
;; block/uuid was particularly bad as it actually changed the page's identity across files
|
||||
disallowed-attributes [:block/name :block/uuid :block/format :block/journal? :block/original-name :block/journal-day
|
||||
:block/created-at :block/updated-at]
|
||||
allowed-attributes [:block/properties :block/tags :block/alias :block/namespace :class/parent :block/type]
|
||||
allowed-attributes [:block/properties :block/tags :block/alias :class/parent :block/type]
|
||||
block-changes (select-keys % allowed-attributes)]
|
||||
(when-let [ignored-attrs (not-empty (apply dissoc % (into disallowed-attributes allowed-attributes)))]
|
||||
(notify-user {:msg (str "Import ignored the following attributes on page " (pr-str (:block/original-name %)) ": "
|
||||
|
||||
@@ -251,16 +251,9 @@
|
||||
(:block/properties-text-values (first blocks))]
|
||||
[properties [] {}])
|
||||
page-map (build-page-map properties invalid-properties properties-text-values file page page-name (assoc options' :from-page page))
|
||||
namespace-pages (let [page (:block/original-name page-map)]
|
||||
(when (text/namespace-page? page)
|
||||
(->> (common-util/split-namespace-pages page)
|
||||
(map (fn [page]
|
||||
(-> (gp-block/page-name->map page true db true date-formatter)
|
||||
(assoc :block/format format)))))))
|
||||
pages (->> (concat
|
||||
[page-map]
|
||||
@ref-pages
|
||||
namespace-pages)
|
||||
@ref-pages)
|
||||
;; remove block references
|
||||
(remove vector?)
|
||||
(remove nil?))
|
||||
|
||||
@@ -133,19 +133,6 @@
|
||||
(get-counts-for-common-attributes db))
|
||||
"Counts for blocks with common block attributes")
|
||||
|
||||
(let [no-name (->> (d/q '[:find (pull ?n [*]) :where [?b :block/namespace ?n]] db)
|
||||
(filter (fn [x]
|
||||
(when-not (:block/original-name (first x))
|
||||
x))))
|
||||
all-namespaces (->> (d/q '[:find (pull ?n [*]) :where [?b :block/namespace ?n]] db)
|
||||
(map (comp :block/original-name first))
|
||||
set)]
|
||||
(is (= #{"term" "setting" "book" "templates" "Query table" "page"
|
||||
"Whiteboard" "Whiteboard/Tool" "Whiteboard/Tool/Shape" "Whiteboard/Object"
|
||||
"Whiteboard/Property" "Community" "Tweet"}
|
||||
all-namespaces)
|
||||
(str "Has correct namespaces: " no-name)))
|
||||
|
||||
(is (empty? (->> (d/q '[:find ?n :where [?b :block/name ?n]] db)
|
||||
(map first)
|
||||
(filter #(string/includes? % "___"))))
|
||||
|
||||
@@ -47,14 +47,6 @@
|
||||
:else
|
||||
(remove-level-space-aux! text block-pattern space? trim-left?)))))
|
||||
|
||||
(defn namespace-page?
|
||||
[page-name]
|
||||
(and (string? page-name)
|
||||
(string/includes? page-name "/")
|
||||
(not (string/starts-with? page-name "../"))
|
||||
(not (string/starts-with? page-name "./"))
|
||||
(not (common-util/url? page-name))))
|
||||
|
||||
(defn parse-non-string-property-value
|
||||
"Return parsed non-string property value or nil if none is found"
|
||||
[v]
|
||||
|
||||
Reference in New Issue
Block a user