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:
Tienson Qin
2024-04-02 23:10:04 +08:00
parent c448e9a0d0
commit 60d4fca0ba
73 changed files with 766 additions and 1343 deletions

View File

@@ -16,7 +16,8 @@
[promesa.core :as p]
[frontend.persist-db.browser :as db-browser]
[frontend.worker.export :as worker-export]
[clojure.edn :as edn]))
[clojure.edn :as edn]
[logseq.db :as ldb]))
;;; TODO: split frontend.handler.export.text related states
(def ^:dynamic *state*
@@ -90,31 +91,23 @@
(mapv remove-block-ast-pos
(mldoc/->edn content format))))))
;; TODO: Enable when unused
#_(defn <get-page-content
([page-name]
(<get-page-content (state/get-current-repo) page-name))
([repo page-name]
(when-let [^object worker @db-browser/*worker]
(.block->content worker repo page-name nil
(pr-str {:export-bullet-indentation (state/get-export-bullet-indentation)})))))
(defn get-page-content
[page-name]
[page-uuid]
(let [repo (state/get-current-repo)
db (db/get-db repo)]
(worker-export/block->content repo db page-name
(worker-export/block->content repo db page-uuid
nil
{:export-bullet-indentation (state/get-export-bullet-indentation)})))
(defn- page-name->ast
[page-name]
(when-let [content (get-page-content page-name)]
(when content
(let [format :markdown]
(removev Properties-block-ast?
(mapv remove-block-ast-pos
(mldoc/->edn content format)))))))
(let [page (db/entity (ldb/get-first-page-by-name (db/get-db) page-name))]
(when-let [content (get-page-content (:block/uuid page))]
(when content
(let [format :markdown]
(removev Properties-block-ast?
(mapv remove-block-ast-pos
(mldoc/->edn content format))))))))
(defn- update-level-in-block-ast-coll
[block-ast-coll origin-level]

View File

@@ -416,15 +416,15 @@
(defn export-blocks-as-html
"options: see also `export-blocks-as-markdown`"
[repo root-block-uuids-or-page-name options]
{:pre [(or (coll? root-block-uuids-or-page-name)
(string? root-block-uuids-or-page-name))]}
[repo root-block-uuids-or-page-uuid options]
{:pre [(or (coll? root-block-uuids-or-page-uuid)
(uuid? root-block-uuids-or-page-uuid))]}
(let [content
(if (string? root-block-uuids-or-page-name)
(if (uuid? root-block-uuids-or-page-uuid)
;; page
(common/get-page-content root-block-uuids-or-page-name)
(common/root-block-uuids->content repo root-block-uuids-or-page-name))
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-name)])
(common/get-page-content root-block-uuids-or-page-uuid)
(common/root-block-uuids->content repo root-block-uuids-or-page-uuid))
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)])
format (or (:block/format first-block) (state/get-preferred-format))]
(export-helper content format options)))

View File

@@ -433,20 +433,20 @@
(defn export-blocks-as-opml
"options: see also `export-blocks-as-markdown`"
[repo root-block-uuids-or-page-name options]
{:pre [(or (coll? root-block-uuids-or-page-name)
(string? root-block-uuids-or-page-name))]}
[repo root-block-uuids-or-page-uuid options]
{:pre [(or (coll? root-block-uuids-or-page-uuid)
(uuid? root-block-uuids-or-page-uuid))]}
(util/profile
:export-blocks-as-opml
(let [content
(if (string? root-block-uuids-or-page-name)
(if (uuid? root-block-uuids-or-page-uuid)
;; page
(common/get-page-content root-block-uuids-or-page-name)
(common/root-block-uuids->content repo root-block-uuids-or-page-name))
title (if (string? root-block-uuids-or-page-name)
root-block-uuids-or-page-name
(common/get-page-content root-block-uuids-or-page-uuid)
(common/root-block-uuids->content repo root-block-uuids-or-page-uuid))
title (if (uuid? root-block-uuids-or-page-uuid)
(:block/original-name (db/entity [:block/name root-block-uuids-or-page-uuid]))
"untitled")
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-name)])
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)])
format (or (:block/format first-block) (state/get-preferred-format))]
(export-helper content format options :title title))))

View File

@@ -509,20 +509,20 @@
:indent-style \"dashes\" | \"spaces\" | \"no-indent\"
:remove-options [:emphasis :page-ref :tag :property]
:other-options {:keep-only-level<=N int :newline-after-block bool}"
[repo root-block-uuids-or-page-name options]
{:pre [(or (coll? root-block-uuids-or-page-name)
(string? root-block-uuids-or-page-name))]}
[repo root-block-uuids-or-page-uuid options]
{:pre [(or (coll? root-block-uuids-or-page-uuid)
(uuid? root-block-uuids-or-page-uuid))]}
(util/profile
:export-blocks-as-markdown
(try
(let [content
(if (string? root-block-uuids-or-page-name)
;; page
(common/get-page-content root-block-uuids-or-page-name)
(common/root-block-uuids->content repo root-block-uuids-or-page-name))
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-name)])
format (or (:block/format first-block) (state/get-preferred-format))]
(export-helper content format options))
(if (uuid? root-block-uuids-or-page-uuid)
;; page
(common/get-page-content root-block-uuids-or-page-uuid)
(common/root-block-uuids->content repo root-block-uuids-or-page-uuid))
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)])
format (or (:block/format first-block) (state/get-preferred-format))]
(export-helper content format options))
(catch :default e
(js/console.error e)))))