Browse Source

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.
Tienson Qin 1 year ago
parent
commit
60d4fca0ba
73 changed files with 773 additions and 1350 deletions
  1. 19 57
      deps/db/src/logseq/db.cljs
  2. 0 1
      deps/db/src/logseq/db/frontend/malli_schema.cljs
  3. 1 1
      deps/db/src/logseq/db/frontend/property/util.cljs
  4. 1 13
      deps/db/src/logseq/db/frontend/rules.cljc
  5. 3 4
      deps/db/src/logseq/db/frontend/schema.cljs
  6. 27 17
      deps/db/src/logseq/db/sqlite/common_db.cljs
  7. 5 6
      deps/graph-parser/src/logseq/graph_parser.cljs
  8. 1 19
      deps/graph-parser/src/logseq/graph_parser/block.cljs
  9. 1 1
      deps/graph-parser/src/logseq/graph_parser/exporter.cljs
  10. 1 8
      deps/graph-parser/src/logseq/graph_parser/extract.cljc
  11. 0 13
      deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs
  12. 0 8
      deps/graph-parser/src/logseq/graph_parser/text.cljs
  13. 18 3
      deps/outliner/src/logseq/outliner/tree.cljs
  14. 4 3
      deps/publishing/test/logseq/publishing/db_test.cljs
  15. 2 2
      src/main/electron/listener.cljs
  16. 7 32
      src/main/frontend/components/block.cljs
  17. 2 2
      src/main/frontend/components/cmdk.cljs
  18. 41 43
      src/main/frontend/components/container.cljs
  19. 0 4
      src/main/frontend/components/container.css
  20. 1 1
      src/main/frontend/components/content.cljs
  21. 5 4
      src/main/frontend/components/editor.cljs
  22. 16 16
      src/main/frontend/components/export.cljs
  23. 0 67
      src/main/frontend/components/hierarchy.cljs
  24. 16 22
      src/main/frontend/components/page.cljs
  25. 19 23
      src/main/frontend/components/page_menu.cljs
  26. 2 1
      src/main/frontend/components/property/value.cljs
  27. 1 7
      src/main/frontend/components/query/builder.cljs
  28. 33 37
      src/main/frontend/components/reference.cljs
  29. 1 1
      src/main/frontend/components/right_sidebar.cljs
  30. 15 12
      src/main/frontend/components/whiteboard.cljs
  31. 2 2
      src/main/frontend/db.cljs
  32. 5 14
      src/main/frontend/db/async.cljs
  33. 1 2
      src/main/frontend/db/debug.cljs
  34. 94 218
      src/main/frontend/db/model.cljs
  35. 0 12
      src/main/frontend/db/query_dsl.cljs
  36. 8 5
      src/main/frontend/db/react.cljs
  37. 1 1
      src/main/frontend/db/rtc/debug_ui.cljs
  38. 22 14
      src/main/frontend/db_worker.cljs
  39. 0 1
      src/main/frontend/extensions/pdf/assets.cljs
  40. 2 2
      src/main/frontend/extensions/slide.cljs
  41. 16 13
      src/main/frontend/extensions/tldraw.cljs
  42. 1 0
      src/main/frontend/extensions/zotero/handler.cljs
  43. 23 20
      src/main/frontend/handler/common/page.cljs
  44. 1 1
      src/main/frontend/handler/db_based/property.cljs
  45. 6 4
      src/main/frontend/handler/editor.cljs
  46. 1 1
      src/main/frontend/handler/events.cljs
  47. 11 18
      src/main/frontend/handler/export/common.cljs
  48. 7 7
      src/main/frontend/handler/export/html.cljs
  49. 9 9
      src/main/frontend/handler/export/opml.cljs
  50. 10 10
      src/main/frontend/handler/export/text.cljs
  51. 45 57
      src/main/frontend/handler/graph.cljs
  52. 41 32
      src/main/frontend/handler/page.cljs
  53. 1 2
      src/main/frontend/handler/query/builder.cljs
  54. 18 24
      src/main/frontend/handler/route.cljs
  55. 4 5
      src/main/frontend/handler/whiteboard.cljs
  56. 24 18
      src/main/frontend/routes.cljs
  57. 4 4
      src/main/frontend/search.cljs
  58. 1 1
      src/main/frontend/worker/db/fix.cljs
  59. 8 10
      src/main/frontend/worker/export.cljs
  60. 1 1
      src/main/frontend/worker/file.cljs
  61. 1 1
      src/main/frontend/worker/file/core.cljs
  62. 5 4
      src/main/frontend/worker/file/page_rename.cljs
  63. 12 39
      src/main/frontend/worker/handler/page.cljs
  64. 75 163
      src/main/frontend/worker/handler/page/rename.cljs
  65. 6 7
      src/main/frontend/worker/rtc/core.cljs
  66. 5 14
      src/main/frontend/worker/search.cljs
  67. 19 17
      src/main/logseq/api.cljs
  68. 1 1
      src/test/frontend/db/db_based_model_test.cljs
  69. 0 51
      src/test/frontend/db/model_test.cljs
  70. 0 15
      src/test/frontend/db/query_dsl_test.cljs
  71. 39 65
      src/test/frontend/worker/handler/page/rename_test.cljs
  72. 1 8
      src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs
  73. 0 29
      src/test/frontend/worker/rtc/rtc_fns_test.cljs

+ 19 - 57
deps/db/src/logseq/db.cljs

@@ -9,7 +9,8 @@
             [clojure.set :as set]
             [clojure.set :as set]
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.entity-plus]
             [logseq.db.frontend.entity-plus]
-            [logseq.db.sqlite.util :as sqlite-util]))
+            [logseq.db.sqlite.util :as sqlite-util]
+            [logseq.db.sqlite.common-db :as sqlite-common-db]))
 
 
 ;; Use it as an input argument for datalog queries
 ;; Use it as an input argument for datalog queries
 (def block-attrs
 (def block-attrs
@@ -107,34 +108,19 @@
           (->> (map #(db-content/update-block-content repo db % (:db/id %))))))
           (->> (map #(db-content/update-block-content repo db % (:db/id %))))))
 
 
 (defn whiteboard-page?
 (defn whiteboard-page?
-  "Given a page name or a page object, check if it is a whiteboard page"
-  [db page]
-  (cond
-    (string? page)
-    (let [page (d/entity db [:block/name (common-util/page-name-sanity-lc page)])]
-      (or
-       (contains? (set (:block/type page)) "whiteboard")
-       (when-let [file (:block/file page)]
-         (when-let [path (:file/path (d/entity db (:db/id file)))]
-           (common-config/whiteboard? path)))))
-
-    (seq page)
-    (contains? (set (:block/type page)) "whiteboard")
-
-    :else false))
+  "Given a page entity or map, check if it is a whiteboard page"
+  [page]
+  (contains? (set (:block/type page)) "whiteboard"))
 
 
 (defn get-page-blocks
 (defn get-page-blocks
   "Return blocks of the designated page, without using cache.
   "Return blocks of the designated page, without using cache.
    page - name / title of the page"
    page - name / title of the page"
-  [db page {:keys [pull-keys]
+  [db page-id {:keys [pull-keys]
             :or {pull-keys '[*]}}]
             :or {pull-keys '[*]}}]
-  (when page
-    (let [page (common-util/page-name-sanity-lc page)
-          page-id (:db/id (d/entity db [:block/name page]))]
-      (when page-id
-        (let [datoms (d/datoms db :avet :block/page page-id)
-              block-eids (mapv :e datoms)]
-          (d/pull-many db pull-keys block-eids))))))
+  (when page-id
+    (let [datoms (d/datoms db :avet :block/page page-id)
+          block-eids (mapv :e datoms)]
+      (d/pull-many db pull-keys block-eids))))
 
 
 (defn get-page-blocks-count
 (defn get-page-blocks-count
   [db page-id]
   [db page-id]
@@ -217,7 +203,7 @@
                                     (= 1 (count children))
                                     (= 1 (count children))
                                     (contains? #{"" "-" "*"} (string/trim (:block/content first-child))))))
                                     (contains? #{"" "-" "*"} (string/trim (:block/content first-child))))))
                                 (not (contains? built-in-pages name))
                                 (not (contains? built-in-pages name))
-                                (not (whiteboard-page? db page))
+                                (not (whiteboard-page? page))
                                 (not (:block/_namespace page))
                                 (not (:block/_namespace page))
                                 (not (contains? (:block/type page) "property"))
                                 (not (contains? (:block/type page) "property"))
                                  ;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility)
                                  ;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility)
@@ -409,38 +395,6 @@
     (when (seq pages)
     (when (seq pages)
       (first pages))))
       (first pages))))
 
 
-(defn get-namespace-pages
-  "Accepts both sanitized and unsanitized namespaces"
-  [db namespace {:keys [db-graph?]}]
-  (assert (string? namespace))
-  (let [namespace (common-util/page-name-sanity-lc namespace)
-        pull-attrs  (cond-> [:db/id :block/name :block/original-name :block/namespace]
-                      (not db-graph?)
-                      (conj {:block/file [:db/id :file/path]}))]
-    (d/q
-     [:find [(list 'pull '?c pull-attrs) '...]
-      :in '$ '% '?namespace
-      :where
-      ['?p :block/name '?namespace]
-      (list 'namespace '?p '?c)]
-     db
-     (:namespace rules/rules)
-     namespace)))
-
-(defn get-pages-by-name-partition
-  [db partition]
-  (when-not (string/blank? partition)
-    (let [partition (common-util/page-name-sanity-lc (string/trim partition))
-          ids (->> (d/datoms db :aevt :block/name)
-                   (filter (fn [datom]
-                             (let [page (:v datom)]
-                               (string/includes? page partition))))
-                   (map :e))]
-      (when (seq ids)
-        (d/pull-many db
-                     '[:db/id :block/name :block/original-name]
-                     ids)))))
-
 (defn get-page
 (defn get-page
   "Get a page given its unsanitized name"
   "Get a page given its unsanitized name"
   [db page-name]
   [db page-name]
@@ -547,6 +501,14 @@
   [db]
   [db]
   (when db (:graph/uuid (d/entity db :logseq.kv/graph-uuid))))
   (when db (:graph/uuid (d/entity db :logseq.kv/graph-uuid))))
 
 
+(def get-first-page-by-name sqlite-common-db/get-first-page-by-name)
+
+(defn page?
+  [block]
+  (and block
+       (:block/name block)
+       (nil? (:block/page block))))
+
 (comment
 (comment
   (defn db-based-graph?
   (defn db-based-graph?
     "Whether the current graph is db-only"
     "Whether the current graph is db-only"

+ 0 - 1
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -65,7 +65,6 @@
    [:block/original-name :string]
    [:block/original-name :string]
    [:block/type {:optional true} [:enum #{"class"} #{"property"} #{"whiteboard"} #{"hidden"}]]
    [:block/type {:optional true} [:enum #{"class"} #{"property"} #{"whiteboard"} #{"hidden"}]]
    [:block/journal? :boolean]
    [:block/journal? :boolean]
-   [:block/namespace {:optional true} :int]
    [:block/alias {:optional true} [:set :int]]
    [:block/alias {:optional true} [:set :int]]
     ;; TODO: Should this be here or in common?
     ;; TODO: Should this be here or in common?
    [:block/path-refs {:optional true} [:set :int]]])
    [:block/path-refs {:optional true} [:set :int]]])

+ 1 - 1
deps/db/src/logseq/db/frontend/property/util.cljs

@@ -40,7 +40,7 @@
 (defn build-property-hidden-page
 (defn build-property-hidden-page
   "Builds a hidden property page for closed values to be transacted"
   "Builds a hidden property page for closed values to be transacted"
   [property]
   [property]
-  (let [page-name (str hidden-page-name-prefix (:db/ident property))]
+  (let [page-name (str hidden-page-name-prefix (:block/uuid property))]
     (-> (sqlite-util/build-new-page page-name)
     (-> (sqlite-util/build-new-page page-name)
         (assoc :block/type #{"hidden"}
         (assoc :block/type #{"hidden"}
                :block/format :markdown))))
                :block/format :markdown))))

+ 1 - 13
deps/db/src/logseq/db/frontend/rules.cljc

@@ -4,14 +4,7 @@
 (def ^:large-vars/data-var rules
 (def ^:large-vars/data-var rules
   "Rules used mainly in frontend.db.model"
   "Rules used mainly in frontend.db.model"
   ;; rule "parent" is optimized for parent node -> child node nesting queries
   ;; rule "parent" is optimized for parent node -> child node nesting queries
-  {:namespace
-   '[[(namespace ?p ?c)
-      [?c :block/namespace ?p]]
-     [(namespace ?p ?c)
-      [?t :block/namespace ?p]
-      (namespace ?t ?c)]]
-
-   :class-parent
+  {:class-parent
    '[[(class-parent ?p ?c)
    '[[(class-parent ?p ?c)
       [?c :class/parent ?p]]
       [?c :class/parent ?p]]
      [(class-parent ?p ?c)
      [(class-parent ?p ?c)
@@ -128,11 +121,6 @@
      [?b :block/page ?bp]
      [?b :block/page ?bp]
      [?bp :block/name ?page-name]]
      [?bp :block/name ?page-name]]
 
 
-   :namespace
-   '[(namespace ?p ?namespace)
-     [?p :block/namespace ?parent]
-     [?parent :block/name ?namespace]]
-
    :property
    :property
    '[(property ?b ?key ?val)
    '[(property ?b ?key ?val)
      [?b :block/properties ?prop]
      [?b :block/properties ?prop]

+ 3 - 4
deps/db/src/logseq/db/frontend/schema.cljs

@@ -24,7 +24,7 @@
                   :db/index true}
                   :db/index true}
    :block/left   {:db/valueType :db.type/ref
    :block/left   {:db/valueType :db.type/ref
                   :db/index true}
                   :db/index true}
-   :block/collapsed? {:db/index true}
+   :block/collapsed? {}
    :block/collapsed-properties {:db/valueType :db.type/ref
    :block/collapsed-properties {:db/valueType :db.type/ref
                                 :db/cardinality :db.cardinality/many}
                                 :db/cardinality :db.cardinality/many}
 
 
@@ -98,8 +98,6 @@
    ;; whether page's is a journal
    ;; whether page's is a journal
    :block/journal? {}
    :block/journal? {}
    :block/journal-day {}
    :block/journal-day {}
-   ;; page's namespace
-   :block/namespace {:db/valueType :db.type/ref}
 
 
    ;; block's file
    ;; block's file
    :block/file {:db/valueType :db.type/ref}
    :block/file {:db/valueType :db.type/ref}
@@ -124,7 +122,8 @@
    (dissoc schema
    (dissoc schema
            :block/properties :block/properties-text-values :block/pre-block? :recent/pages :file/handle :block/file
            :block/properties :block/properties-text-values :block/pre-block? :recent/pages :file/handle :block/file
            :block/properties-order)
            :block/properties-order)
-   {:class/parent {:db/valueType :db.type/ref
+   {:block/name {:db/index true}        ; remove db/unique for :block/name
+    :class/parent {:db/valueType :db.type/ref
                    :db/index true}
                    :db/index true}
     :file/last-modified-at {}
     :file/last-modified-at {}
     :asset/uuid {:db/unique :db.unique/identity}
     :asset/uuid {:db/unique :db.unique/identity}

+ 27 - 17
deps/db/src/logseq/db/sqlite/common_db.cljs

@@ -8,6 +8,15 @@
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
             [logseq.common.config :as common-config]))
             [logseq.common.config :as common-config]))
 
 
+(defn get-pages-by-name
+  [db page-name]
+  (d/datoms db :avet :block/name (common-util/page-name-sanity-lc page-name)))
+
+(defn get-first-page-by-name
+  "Return the oldest page"
+  [db page-name]
+  (first (sort (map :e (get-pages-by-name db page-name)))))
+
 (comment
 (comment
   (defn- get-built-in-files
   (defn- get-built-in-files
     [db]
     [db]
@@ -62,11 +71,10 @@
   (assoc b :block.temp/fully-loaded? true))
   (assoc b :block.temp/fully-loaded? true))
 
 
 (defn get-block-and-children
 (defn get-block-and-children
-  [db name children?]
-  (let [uuid? (common-util/uuid-string? name)
-        block (when uuid?
-                (let [id (uuid name)]
-                  (d/entity db [:block/uuid id])))
+  [db id children?]
+  (let [block (d/entity db (if (uuid? id)
+                             [:block/uuid id]
+                             id))
         get-children (fn [children]
         get-children (fn [children]
                        (let [long-page? (> (count children) 500)]
                        (let [long-page? (> (count children) 500)]
                          (if long-page?
                          (if long-page?
@@ -76,16 +84,16 @@
                            (->> (d/pull-many db '[*] (map :db/id children))
                            (->> (d/pull-many db '[*] (map :db/id children))
                                 (map #(with-block-refs db %))
                                 (map #(with-block-refs db %))
                                 (map mark-block-fully-loaded)))))]
                                 (map mark-block-fully-loaded)))))]
-    (if (and block (not (:block/name block))) ; not a page
-      (let [block' (->> (d/pull db '[*] (:db/id block))
-                        (with-parent-and-left db)
-                        (with-block-refs db)
-                        mark-block-fully-loaded)]
-        (cond->
-         {:block block'}
-          children?
-          (assoc :children (get-children (:block/_parent block)))))
-      (when-let [block (or block (d/entity db [:block/name name]))]
+    (when block
+      (if (:block/page block) ; not a page
+        (let [block' (->> (d/pull db '[*] (:db/id block))
+                          (with-parent-and-left db)
+                          (with-block-refs db)
+                          mark-block-fully-loaded)]
+          (cond->
+           {:block block'}
+            children?
+            (assoc :children (get-children (:block/_parent block)))))
         (cond->
         (cond->
          {:block (->> (d/pull db '[*] (:db/id block))
          {:block (->> (d/pull db '[*] (:db/id block))
                       (with-tags db)
                       (with-tags db)
@@ -125,7 +133,8 @@
 (defn get-favorites
 (defn get-favorites
   "Favorites page and its blocks"
   "Favorites page and its blocks"
   [db]
   [db]
-  (let [{:keys [block children]} (get-block-and-children db common-config/favorites-page-name true)]
+  (let [page-id (get-first-page-by-name db common-config/favorites-page-name)
+        {:keys [block children]} (get-block-and-children db page-id true)]
     (when block
     (when block
       (concat [block]
       (concat [block]
               (->> (keep :block/link children)
               (->> (keep :block/link children)
@@ -135,7 +144,8 @@
 
 
 (defn get-full-page-and-blocks
 (defn get-full-page-and-blocks
   [db page-name]
   [db page-name]
-  (let [data (get-block-and-children db (common-util/page-name-sanity-lc page-name) true)
+  (let [page-id (get-first-page-by-name db page-name)
+        data (get-block-and-children db page-id true)
         result (first (tree-seq map? :children data))]
         result (first (tree-seq map? :children data))]
     (cons (:block result)
     (cons (:block result)
           (map #(dissoc % :children) (:children result)))))
           (map #(dissoc % :children) (:children result)))))

+ 5 - 6
deps/graph-parser/src/logseq/graph_parser.cljs

@@ -23,12 +23,11 @@
   [db file-path]
   [db file-path]
   (ffirst
   (ffirst
    (d/q
    (d/q
-    '[:find ?page-name
+    '[:find ?page
       :in $ ?path
       :in $ ?path
       :where
       :where
       [?file :file/path ?path]
       [?file :file/path ?path]
-      [?page :block/file ?file]
-      [?page :block/original-name ?page-name]]
+      [?page :block/file ?file]]
     db
     db
     file-path)))
     file-path)))
 
 
@@ -50,9 +49,9 @@
   UUIDs."
   UUIDs."
   [db file-page file-path retain-uuid-blocks]
   [db file-page file-path retain-uuid-blocks]
   (let [existing-file-page (get-file-page db file-path)
   (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)
                        pages-to-clear)
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
     (retract-blocks-tx (distinct blocks) retain-uuids)))
     (retract-blocks-tx (distinct blocks) retain-uuids)))

+ 1 - 19
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -292,8 +292,6 @@
     (and original-page-name (string? original-page-name))
     (and original-page-name (string? original-page-name))
     (let [original-page-name (common-util/remove-boundary-slashes 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)
           [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]))
           page-entity (some-> db (d/entity [:block/name page-name]))
           original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
           original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
       (merge
       (merge
@@ -305,10 +303,6 @@
                                (uuid? with-id?) with-id?)
                                (uuid? with-id?) with-id?)
                          (d/squuid))]
                          (d/squuid))]
            {:block/uuid new-uuid}))
            {: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
        (when (and with-timestamp? (not page-entity)) ;; Only assign timestamp on creating new entity
          (let [current-ms (common-util/time-ms)]
          (let [current-ms (common-util/time-ms)]
            {:block/created-at current-ms
            {:block/created-at current-ms
@@ -353,19 +347,7 @@
     (let [*name->id (atom {})
     (let [*name->id (atom {})
           ref->map-fn (fn [*col _tag?]
           ref->map-fn (fn [*col _tag?]
                         (let [col (remove string/blank? @*col)
                         (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
                           (map
                            (fn [item]
                            (fn [item]
                              (let [macro? (and (map? item)
                              (let [macro? (and (map? item)

+ 1 - 1
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -603,7 +603,7 @@
                                 ;; block/uuid was particularly bad as it actually changed the page's identity across files
                                 ;; 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
                                 disallowed-attributes [:block/name :block/uuid :block/format :block/journal? :block/original-name :block/journal-day
                                                        :block/created-at :block/updated-at]
                                                        :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)]
                                 block-changes (select-keys % allowed-attributes)]
                             (when-let [ignored-attrs (not-empty (apply dissoc % (into disallowed-attributes 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 %)) ": "
                               (notify-user {:msg (str "Import ignored the following attributes on page " (pr-str (:block/original-name %)) ": "

+ 1 - 8
deps/graph-parser/src/logseq/graph_parser/extract.cljc

@@ -251,16 +251,9 @@
              (:block/properties-text-values (first blocks))]
              (:block/properties-text-values (first blocks))]
             [properties [] {}])
             [properties [] {}])
           page-map (build-page-map properties invalid-properties properties-text-values file page page-name (assoc options' :from-page page))
           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
           pages (->> (concat
                       [page-map]
                       [page-map]
-                      @ref-pages
-                      namespace-pages)
+                      @ref-pages)
                      ;; remove block references
                      ;; remove block references
                      (remove vector?)
                      (remove vector?)
                      (remove nil?))
                      (remove nil?))

+ 0 - 13
deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs

@@ -133,19 +133,6 @@
            (get-counts-for-common-attributes db))
            (get-counts-for-common-attributes db))
         "Counts for blocks with common block attributes")
         "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)
     (is (empty? (->> (d/q '[:find ?n :where [?b :block/name ?n]] db)
                      (map first)
                      (map first)
                      (filter #(string/includes? % "___"))))
                      (filter #(string/includes? % "___"))))

+ 0 - 8
deps/graph-parser/src/logseq/graph_parser/text.cljs

@@ -47,14 +47,6 @@
        :else
        :else
        (remove-level-space-aux! text block-pattern space? trim-left?)))))
        (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
 (defn parse-non-string-property-value
   "Return parsed non-string property value or nil if none is found"
   "Return parsed non-string property value or nil if none is found"
   [v]
   [v]

+ 18 - 3
deps/outliner/src/logseq/outliner/tree.cljs

@@ -42,16 +42,31 @@
 
 
 (defn- get-root-and-page
 (defn- get-root-and-page
   [db root-id]
   [db root-id]
-  (if (string? root-id)
+  (cond
+    (uuid? root-id)
+    (let [e (d/entity db [:block/uuid root-id])]
+      (if (:block/page e)
+        [false e]
+        [true e]))
+
+    (number? root-id)
+    (let [e (d/entity db root-id)]
+      (if (:block/page e)
+        [false e]
+        [true e]))
+
+    (string? root-id)
     (if-let [id (parse-uuid root-id)]
     (if-let [id (parse-uuid root-id)]
       [false (d/entity db [:block/uuid id])]
       [false (d/entity db [:block/uuid id])]
-      [true (d/entity db [:block/name (string/lower-case root-id)])])
+      [true (d/entity db (ldb/get-first-page-by-name db root-id))])
+
+    :else
     [false root-id]))
     [false root-id]))
 
 
 (defn blocks->vec-tree
 (defn blocks->vec-tree
   "`blocks` need to be in the same page."
   "`blocks` need to be in the same page."
   [repo db blocks root-id]
   [repo db blocks root-id]
-  (let [[page? root] (get-root-and-page db (str root-id))]
+  (let [[page? root] (get-root-and-page db root-id)]
     (if-not root ; custom query
     (if-not root ; custom query
       blocks
       blocks
       (let [result (blocks->vec-tree-aux repo db blocks root)]
       (let [result (blocks->vec-tree-aux repo db blocks root)]

+ 4 - 3
deps/publishing/test/logseq/publishing/db_test.cljs

@@ -4,7 +4,8 @@
             [logseq.publishing.db :as publish-db]
             [logseq.publishing.db :as publish-db]
             [logseq.graph-parser :as graph-parser]
             [logseq.graph-parser :as graph-parser]
             [datascript.core :as d]
             [datascript.core :as d]
-            [logseq.graph-parser.db :as gp-db]))
+            [logseq.graph-parser.db :as gp-db]
+            [logseq.db :as ldb]))
 
 
 (deftest clean-export!
 (deftest clean-export!
   (let [conn (gp-db/start-conn)
   (let [conn (gp-db/start-conn)
@@ -56,8 +57,8 @@
         "Contains all pages that have been marked public")
         "Contains all pages that have been marked public")
     (is (not (contains? exported-pages "page1"))
     (is (not (contains? exported-pages "page1"))
         "Doesn't contain private page")
         "Doesn't contain private page")
-    (is (seq (d/entity filtered-db [:block/name "page2-alias"]))
-          "Alias of public page is exported")
+    (is (seq (ldb/get-pages-by-name filtered-db "page2-alias"))
+        "Alias of public page is exported")
     (is (= #{"page2" "page3"} exported-block-pages)
     (is (= #{"page2" "page3"} exported-block-pages)
         "Only exports blocks from public pages")
         "Only exports blocks from public pages")
     (is (= ["thumb-on-fire_1648822523866_0.PNG"] assets)
     (is (= ["thumb-on-fire_1648822523866_0.PNG"] assets)

+ 2 - 2
src/main/electron/listener.cljs

@@ -87,13 +87,13 @@
                          ;; No error handling required, as a page name is always valid
                          ;; No error handling required, as a page name is always valid
                          ;; Open new page if the page does not exist
                          ;; Open new page if the page does not exist
                          (if whiteboard?
                          (if whiteboard?
-                           (route-handler/redirect-to-whiteboard! page-name {:block-id block-id})
+                           (route-handler/redirect-to-page! page-name {:block-id block-id})
                            (editor-handler/insert-first-page-block-if-not-exists! db-page-name)))
                            (editor-handler/insert-first-page-block-if-not-exists! db-page-name)))
 
 
                        block-id
                        block-id
                        (if-let [block (db-model/get-block-by-uuid block-id)]
                        (if-let [block (db-model/get-block-by-uuid block-id)]
                          (if (pu/shape-block? block)
                          (if (pu/shape-block? block)
-                           (route-handler/redirect-to-whiteboard! (get-in block [:block/page :block/name]) {:block-id block-id})
+                           (route-handler/redirect-to-page! (get-in block [:block/page :block/uuid]) {:block-id block-id})
                            (route-handler/redirect-to-page! block-id))
                            (route-handler/redirect-to-page! block-id))
                          (notification/show! (str "Open link failed. Block-id `" block-id "` doesn't exist in the graph.") :error false))
                          (notification/show! (str "Open link failed. Block-id `" block-id "` doesn't exist in the graph.") :error false))
 
 

+ 7 - 32
src/main/frontend/components/block.cljs

@@ -535,7 +535,7 @@
          (whiteboard-handler/closest-shape (.-target e)))
          (whiteboard-handler/closest-shape (.-target e)))
 
 
         whiteboard-page?
         whiteboard-page?
-        (route-handler/redirect-to-whiteboard! page-name)
+        (route-handler/redirect-to-page! page-name)
 
 
         (nil? page)
         (nil? page)
         (state/pub-event! [:page/create page-name-in-block])
         (state/pub-event! [:page/create page-name-in-block])
@@ -575,7 +575,7 @@
                (and tag? display-close-button?) (str " pl-4"))
                (and tag? display-close-button?) (str " pl-4"))
       :data-ref page-name
       :data-ref page-name
       :draggable true
       :draggable true
-      :on-drag-start (fn [e] (editor-handler/block->data-transfer! page-name-in-block e))
+      :on-drag-start (fn [e] (editor-handler/block->data-transfer! page-name-in-block e true))
       :on-mouse-over #(reset! *hover? true)
       :on-mouse-over #(reset! *hover? true)
       :on-mouse-leave #(reset! *hover? false)
       :on-mouse-leave #(reset! *hover? false)
       :on-pointer-down (fn [e]
       :on-pointer-down (fn [e]
@@ -958,8 +958,8 @@
                           ;; pdf annotation
                           ;; pdf annotation
                         [:annotation true] (pdf-assets/open-block-ref! block)
                         [:annotation true] (pdf-assets/open-block-ref! block)
 
 
-                        [:whiteboard-shape true] (route-handler/redirect-to-whiteboard!
-                                                  (get-in block [:block/page :block/name]) {:block-id block-id})
+                        [:whiteboard-shape true] (route-handler/redirect-to-page!
+                                                  (get-in block [:block/page :block/uuid]) {:block-id block-id})
 
 
                           ;; default open block page
                           ;; default open block page
                         :else (route-handler/redirect-to-page! id))))))}
                         :else (route-handler/redirect-to-page! id))))))}
@@ -1486,27 +1486,6 @@
           format (get-in config [:block :block/format] :markdown)]
           format (get-in config [:block :block/format] :markdown)]
       (render-macro config name arguments macro-content format))))
       (render-macro config name arguments macro-content format))))
 
 
-(rum/defc namespace-hierarchy-aux
-  [config namespace children]
-  [:ul
-   (for [child children]
-     [:li {:key (str "namespace-" namespace "-" (:db/id child))}
-      (let [shorten-name (some-> (or (:block/original-name child) (:block/name child))
-                                 (string/split "/")
-                                 last)]
-        (page-cp {:label shorten-name} child))
-      (when (seq (:namespace/children child))
-        (namespace-hierarchy-aux config (:block/name child)
-                                 (:namespace/children child)))])])
-
-(rum/defc namespace-hierarchy
-  [config namespace children]
-  [:div.namespace
-   [:div.font-medium.flex.flex-row.items-center.pb-2
-    [:span.text-sm.mr-1 "Namespace "]
-    (page-cp config {:block/name namespace})]
-   (namespace-hierarchy-aux config namespace children)])
-
 (defn- macro-cp
 (defn- macro-cp
   [config options]
   [config options]
   (let [{:keys [name arguments]} options
   (let [{:keys [name arguments]} options
@@ -1525,11 +1504,7 @@
       (macro-function-cp config arguments)
       (macro-function-cp config arguments)
 
 
       (= name "namespace")
       (= name "namespace")
-      (let [namespace (first arguments)]
-        (when-not (string/blank? namespace)
-          (let [namespace (string/lower-case (page-ref/get-page-name! namespace))
-                children (model/get-namespace-hierarchy (state/get-current-repo) namespace)]
-            (namespace-hierarchy config namespace children))))
+      [:div.warning "Namespace has been deprecated, use tags instead"]
 
 
       (= name "youtube")
       (= name "youtube")
       (when-let [url (first arguments)]
       (when-let [url (first arguments)]
@@ -1727,7 +1702,7 @@
       (state/conj-selection-block! (gdom/getElement block-id) :down)
       (state/conj-selection-block! (gdom/getElement block-id) :down)
       (editor-handler/highlight-block! uuid)))
       (editor-handler/highlight-block! uuid)))
 
 
-  (editor-handler/block->data-transfer! uuid event)
+  (editor-handler/block->data-transfer! uuid event false)
   (.setData (gobj/get event "dataTransfer")
   (.setData (gobj/get event "dataTransfer")
             "block-dom-id"
             "block-dom-id"
             block-id)
             block-id)
@@ -1738,7 +1713,7 @@
   [e block uuid]
   [e block uuid]
   (cond
   (cond
     (pu/shape-block? block)
     (pu/shape-block? block)
-    (route-handler/redirect-to-whiteboard! (get-in block [:block/page :block/name]) {:block-id uuid})
+    (route-handler/redirect-to-page! (get-in block [:block/page :block/uuid]) {:block-id uuid})
 
 
     (gobj/get e "shiftKey")
     (gobj/get e "shiftKey")
     (do
     (do

+ 2 - 2
src/main/frontend/components/cmdk.cljs

@@ -410,7 +410,7 @@
           page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])
           page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])
           original-name (:block/original-name page)]
           original-name (:block/original-name page)]
       (if (= (:block/type page) "whiteboard")
       (if (= (:block/type page) "whiteboard")
-        (route-handler/redirect-to-whiteboard! original-name)
+        (route-handler/redirect-to-page! original-name)
         (route-handler/redirect-to-page! original-name)))
         (route-handler/redirect-to-page! original-name)))
     (state/close-modal!)))
     (state/close-modal!)))
 
 
@@ -425,7 +425,7 @@
            (let [page-name (:block/name page)]
            (let [page-name (:block/name page)]
              (cond
              (cond
                (= (:block/type page) "whiteboard")
                (= (:block/type page) "whiteboard")
-               (route-handler/redirect-to-whiteboard! page-name {:block-id block-id})
+               (route-handler/redirect-to-page! page-name {:block-id block-id})
                (model/parents-collapsed? (state/get-current-repo) block-id)
                (model/parents-collapsed? (state/get-current-repo) block-id)
                (route-handler/redirect-to-page! block-id)
                (route-handler/redirect-to-page! block-id)
                :else
                :else

+ 41 - 43
src/main/frontend/components/container.cljs

@@ -82,42 +82,42 @@
         source-page (db-model/get-alias-source-page (state/get-current-repo) name)
         source-page (db-model/get-alias-source-page (state/get-current-repo) name)
         ctx-icon #(shui/tabler-icon %1 {:class "scale-90 pr-1 opacity-80"})
         ctx-icon #(shui/tabler-icon %1 {:class "scale-90 pr-1 opacity-80"})
         open-in-sidebar #(when-let [page-entity (and (not whiteboard-page?)
         open-in-sidebar #(when-let [page-entity (and (not whiteboard-page?)
-                                                  (if (empty? source-page)
-                                                    (db/entity [:block/name name]) source-page))]
+                                                     (if (empty? source-page)
+                                                       (db/entity [:block/name name]) source-page))]
                            (state/sidebar-add-block!
                            (state/sidebar-add-block!
-                             (state/get-current-repo)
-                             (:db/id page-entity)
-                             :page))
+                            (state/get-current-repo)
+                            (:db/id page-entity)
+                            :page))
         x-menu-content (fn []
         x-menu-content (fn []
                          (let [x-menu-item shui/dropdown-menu-item
                          (let [x-menu-item shui/dropdown-menu-item
                                x-menu-shortcut shui/dropdown-menu-shortcut]
                                x-menu-shortcut shui/dropdown-menu-shortcut]
                            [:<>
                            [:<>
                             (when-not recent?
                             (when-not recent?
                               (x-menu-item
                               (x-menu-item
-                                {:on-click #(page-handler/<unfavorite-page! original-name)}
-                                (ctx-icon "star-off")
-                                (t :page/unfavorite)
-                                (x-menu-shortcut (when-let [binding (shortcut-dh/shortcut-binding :command/toggle-favorite)]
-                                                   (some-> binding
-                                                     (first)
-                                                     (shortcut-utils/decorate-binding))))))
+                               {:on-click #(page-handler/<unfavorite-page! original-name)}
+                               (ctx-icon "star-off")
+                               (t :page/unfavorite)
+                               (x-menu-shortcut (when-let [binding (shortcut-dh/shortcut-binding :command/toggle-favorite)]
+                                                  (some-> binding
+                                                          (first)
+                                                          (shortcut-utils/decorate-binding))))))
                             (when-let [page-fpath (and (util/electron?) file-rpath
                             (when-let [page-fpath (and (util/electron?) file-rpath
-                                                    (config/get-repo-fpath (state/get-current-repo) file-rpath))]
+                                                       (config/get-repo-fpath (state/get-current-repo) file-rpath))]
                               [:<>
                               [:<>
                                (x-menu-item
                                (x-menu-item
-                                 {:on-click #(ipc/ipc :openFileInFolder page-fpath)}
-                                 (ctx-icon "folder")
-                                 (t :page/open-in-finder))
+                                {:on-click #(ipc/ipc :openFileInFolder page-fpath)}
+                                (ctx-icon "folder")
+                                (t :page/open-in-finder))
 
 
                                (x-menu-item
                                (x-menu-item
-                                 {:on-click #(js/window.apis.openPath page-fpath)}
-                                 (ctx-icon "file")
-                                 (t :page/open-with-default-app))])
+                                {:on-click #(js/window.apis.openPath page-fpath)}
+                                (ctx-icon "file")
+                                (t :page/open-with-default-app))])
                             (x-menu-item
                             (x-menu-item
-                              {:on-click open-in-sidebar}
-                              (ctx-icon "layout-sidebar-right")
-                              (t :content/open-in-sidebar)
-                              (x-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))]))]
+                             {:on-click open-in-sidebar}
+                             (ctx-icon "layout-sidebar-right")
+                             (t :content/open-in-sidebar)
+                             (x-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))]))]
 
 
     ;; TODO: move to standalone component
     ;; TODO: move to standalone component
     [:a.flex.items-center.justify-between.relative.group
     [:a.flex.items-center.justify-between.relative.group
@@ -126,32 +126,30 @@
         (let [name (if (empty? source-page) name (:block/name source-page))]
         (let [name (if (empty? source-page) name (:block/name source-page))]
           (if (gobj/get e "shiftKey")
           (if (gobj/get e "shiftKey")
             (open-in-sidebar)
             (open-in-sidebar)
-            (if whiteboard-page?
-              (route-handler/redirect-to-whiteboard! name {:click-from-recent? recent?})
-              (route-handler/redirect-to-page! name {:click-from-recent? recent?})))))
+            (route-handler/redirect-to-page! name {:click-from-recent? recent?}))))
       :on-context-menu (fn [^js e]
       :on-context-menu (fn [^js e]
                          (shui/popup-show! e (x-menu-content)
                          (shui/popup-show! e (x-menu-content)
-                           {:as-dropdown? true
-                            :content-props {:on-click (fn [] (shui/popup-hide!))
-                                            :class "w-60"}})
+                                           {:as-dropdown? true
+                                            :content-props {:on-click (fn [] (shui/popup-hide!))
+                                                            :class "w-60"}})
                          (util/stop e))}
                          (util/stop e))}
      [:span.page-icon.ml-3.justify-center (if whiteboard-page? (ui/icon "whiteboard" {:extension? true}) icon)]
      [:span.page-icon.ml-3.justify-center (if whiteboard-page? (ui/icon "whiteboard" {:extension? true}) icon)]
      [:span.page-title {:class (when untitled? "opacity-50")}
      [:span.page-title {:class (when untitled? "opacity-50")}
       (if untitled? (t :untitled)
       (if untitled? (t :untitled)
-                    (pdf-utils/fix-local-asset-pagename original-name))]
+          (pdf-utils/fix-local-asset-pagename original-name))]
 
 
      ;; dots trigger
      ;; dots trigger
      (shui/button
      (shui/button
-       {:size :sm
-        :variant :ghost
-        :class "absolute right-2 top-0 px-1.5 scale-75 opacity-30 hidden group-hover:block hover:opacity-80 active:opacity-100"
-        :on-click #(do
-                     (shui/popup-show! (.-target %) (x-menu-content)
-                       {:as-dropdown? true
-                        :content-props {:on-click (fn [] (shui/popup-hide!))
-                                        :class "w-60"}})
-                     (util/stop %))}
-       [:i.relative {:style {:top "1px"}} (shui/tabler-icon "dots")])]))
+      {:size :sm
+       :variant :ghost
+       :class "absolute right-2 top-0 px-1.5 scale-75 opacity-30 hidden group-hover:block hover:opacity-80 active:opacity-100"
+       :on-click #(do
+                    (shui/popup-show! (.-target %) (x-menu-content)
+                                      {:as-dropdown? true
+                                       :content-props {:on-click (fn [] (shui/popup-hide!))
+                                                       :class "w-60"}})
+                    (util/stop %))}
+      [:i.relative {:style {:top "1px"}} (shui/tabler-icon "dots")])]))
 
 
 ;; Fall back to default if icon is undefined or empty
 ;; Fall back to default if icon is undefined or empty
 
 
@@ -203,7 +201,7 @@
            {:key name
            {:key name
             :title name
             :title name
             :draggable true
             :draggable true
-            :on-drag-start (fn [event] (editor-handler/block->data-transfer! name event))
+            :on-drag-start (fn [event] (editor-handler/block->data-transfer! name event true))
             :data-ref name}
             :data-ref name}
            (page-name name (icon/get-page-icon entity {}) true)]))])))
            (page-name name (icon/get-page-icon entity {}) true)]))])))
 
 
@@ -838,7 +836,7 @@
                   block-el (.closest target ".bullet-container[blockid]")
                   block-el (.closest target ".bullet-container[blockid]")
                   block-id (some-> block-el (.getAttribute "blockid"))
                   block-id (some-> block-el (.getAttribute "blockid"))
                   {:keys [block block-ref]} (state/sub :block-ref/context)
                   {:keys [block block-ref]} (state/sub :block-ref/context)
-                  {:keys [page]} (state/sub :page-title/context)]
+                  {:keys [page page-entity]} (state/sub :page-title/context)]
 
 
               (let [show!
               (let [show!
                     (fn [content]
                     (fn [content]
@@ -851,7 +849,7 @@
                     (cond
                     (cond
                       page
                       page
                       (do
                       (do
-                        (show! (cp-content/page-title-custom-context-menu-content page))
+                        (show! (cp-content/page-title-custom-context-menu-content page-entity))
                         (state/set-state! :page-title/context nil))
                         (state/set-state! :page-title/context nil))
 
 
                       block-ref
                       block-ref

+ 0 - 4
src/main/frontend/components/container.css

@@ -745,10 +745,6 @@
       }
       }
     }
     }
   }
   }
-
-  .page-hierarchy {
-    @apply pl-[28px];
-  }
 }
 }
 
 
 .cp__sidebar-main-content[data-is-full-width='true'] {
 .cp__sidebar-main-content[data-is-full-width='true'] {

+ 1 - 1
src/main/frontend/components/content.cljs

@@ -375,7 +375,7 @@
 
 
 (rum/defc page-title-custom-context-menu-content
 (rum/defc page-title-custom-context-menu-content
   [page]
   [page]
-  (when-not (string/blank? page)
+  (when page
     (let [page-menu-options (page-menu/page-menu page)]
     (let [page-menu-options (page-menu/page-menu page)]
       [:.menu-links-wrapper
       [:.menu-links-wrapper
        (for [{:keys [title options]} page-menu-options]
        (for [{:keys [title options]} page-menu-options]

+ 5 - 4
src/main/frontend/components/editor.cljs

@@ -29,7 +29,8 @@
             [promesa.core :as p]
             [promesa.core :as p]
             [react-draggable]
             [react-draggable]
             [rum.core :as rum]
             [rum.core :as rum]
-            [frontend.config :as config]))
+            [frontend.config :as config]
+            [logseq.db :as ldb]))
 
 
 (rum/defc commands < rum/reactive
 (rum/defc commands < rum/reactive
   [id format]
   [id format]
@@ -108,16 +109,16 @@
                         (common-util/safe-subs value (+ (count q) 4 pos)))]
                         (common-util/safe-subs value (+ (count q) 4 pos)))]
         (state/set-edit-content! (.-id input) value')
         (state/set-edit-content! (.-id input) value')
         (state/clear-editor-action!)
         (state/clear-editor-action!)
-        (p/let [page-name (util/page-name-sanity-lc chosen-item)
-                page (db/entity [:block/name page-name])
+        (p/let [page (db/entity (ldb/get-first-page-by-name (db/get-db) chosen-item))
                 _ (when-not page (page-handler/<create! chosen-item {:redirect? false
                 _ (when-not page (page-handler/<create! chosen-item {:redirect? false
                                                                      :create-first-block? false}))
                                                                      :create-first-block? false}))
+                page' (db/entity (ldb/get-first-page-by-name (db/get-db) chosen-item))
                 current-block (state/get-edit-block)]
                 current-block (state/get-edit-block)]
           (editor-handler/api-insert-new-block! chosen-item
           (editor-handler/api-insert-new-block! chosen-item
                                                 {:block-uuid (:block/uuid current-block)
                                                 {:block-uuid (:block/uuid current-block)
                                                  :sibling? true
                                                  :sibling? true
                                                  :replace-empty-target? true
                                                  :replace-empty-target? true
-                                                 :other-attrs {:block/link (:db/id (db/entity [:block/name page-name]))}}))))
+                                                 :other-attrs {:block/link (:db/id page')}}))))
     (page-handler/on-chosen-handler input id q pos format)))
     (page-handler/on-chosen-handler input id q pos format)))
 
 
 (rum/defc page-search-aux
 (rum/defc page-search-aux

+ 16 - 16
src/main/frontend/components/export.cljs

@@ -142,7 +142,7 @@
                  (reset! (::text-indent-style state) (state/get-export-block-text-indent-style))
                  (reset! (::text-indent-style state) (state/get-export-block-text-indent-style))
                  (reset! (::text-other-options state) (state/get-export-block-text-other-options))
                  (reset! (::text-other-options state) (state/get-export-block-text-other-options))
                  state)}
                  state)}
-  [state root-block-uuids-or-page-name {:keys [whiteboard?] :as options}]
+  [state root-block-uuids-or-page-uuid {:keys [whiteboard?] :as options}]
   (let [tp @*export-block-type
   (let [tp @*export-block-type
         *text-other-options (::text-other-options state)
         *text-other-options (::text-other-options state)
         *text-remove-options (::text-remove-options state)
         *text-remove-options (::text-remove-options state)
@@ -157,21 +157,21 @@
          (ui/button "Text"
          (ui/button "Text"
            :class "mr-4 w-20"
            :class "mr-4 w-20"
            :on-click #(do (reset! *export-block-type :text)
            :on-click #(do (reset! *export-block-type :text)
-                          (reset! *content (export-helper root-block-uuids-or-page-name))))
+                          (reset! *content (export-helper root-block-uuids-or-page-uuid))))
          (ui/button "OPML"
          (ui/button "OPML"
            :class "mr-4 w-20"
            :class "mr-4 w-20"
            :on-click #(do (reset! *export-block-type :opml)
            :on-click #(do (reset! *export-block-type :opml)
-                          (reset! *content (export-helper root-block-uuids-or-page-name))))
+                          (reset! *content (export-helper root-block-uuids-or-page-uuid))))
          (ui/button "HTML"
          (ui/button "HTML"
            :class "mr-4 w-20"
            :class "mr-4 w-20"
            :on-click #(do (reset! *export-block-type :html)
            :on-click #(do (reset! *export-block-type :html)
-                          (reset! *content (export-helper root-block-uuids-or-page-name))))
-         (when-not (seq? root-block-uuids-or-page-name)
+                          (reset! *content (export-helper root-block-uuids-or-page-uuid))))
+         (when-not (seq? root-block-uuids-or-page-uuid)
            (ui/button "PNG"
            (ui/button "PNG"
              :class "w-20"
              :class "w-20"
              :on-click #(do (reset! *export-block-type :png)
              :on-click #(do (reset! *export-block-type :png)
                             (reset! *content nil)
                             (reset! *content nil)
-                            (get-image-blob root-block-uuids-or-page-name (merge options {:transparent-bg? false}) (fn [blob] (reset! *content blob))))))])
+                            (get-image-blob root-block-uuids-or-page-uuid (merge options {:transparent-bg? false}) (fn [blob] (reset! *content blob))))))])
 
 
       (if (= :png tp)
       (if (= :png tp)
         [:div.flex.items-center.justify-center.relative
         [:div.flex.items-center.justify-center.relative
@@ -186,7 +186,7 @@
          (ui/checkbox {:class "mr-2 ml-4"
          (ui/checkbox {:class "mr-2 ml-4"
                        :on-change (fn [e]
                        :on-change (fn [e]
                                     (reset! *content nil)
                                     (reset! *content nil)
-                                    (get-image-blob root-block-uuids-or-page-name (merge options {:transparent-bg? e.currentTarget.checked}) (fn [blob] (reset! *content blob))))})]
+                                    (get-image-blob root-block-uuids-or-page-uuid (merge options {:transparent-bg? e.currentTarget.checked}) (fn [blob] (reset! *content blob))))})]
         (let [options (->> text-indent-style-options
         (let [options (->> text-indent-style-options
                         (mapv (fn [opt]
                         (mapv (fn [opt]
                                 (if (= @*text-indent-style (:label opt))
                                 (if (= @*text-indent-style (:label opt))
@@ -202,7 +202,7 @@
                                 (let [value (util/evalue e)]
                                 (let [value (util/evalue e)]
                                   (state/set-export-block-text-indent-style! value)
                                   (state/set-export-block-text-indent-style! value)
                                   (reset! *text-indent-style value)
                                   (reset! *text-indent-style value)
-                                  (reset! *content (export-helper root-block-uuids-or-page-name))))}
+                                  (reset! *content (export-helper root-block-uuids-or-page-uuid))))}
                   (for [{:keys [label value selected]} options]
                   (for [{:keys [label value selected]} options]
                     [:option (cond->
                     [:option (cond->
                                {:key label
                                {:key label
@@ -217,7 +217,7 @@
                           :on-change (fn [e]
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :page-ref)
                                        (state/update-export-block-text-remove-options! e :page-ref)
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
-                                       (reset! *content (export-helper root-block-uuids-or-page-name)))})
+                                       (reset! *content (export-helper root-block-uuids-or-page-uuid)))})
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
              "[[text]] -> text"]
              "[[text]] -> text"]
 
 
@@ -227,7 +227,7 @@
                           :on-change (fn [e]
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :emphasis)
                                        (state/update-export-block-text-remove-options! e :emphasis)
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
-                                       (reset! *content (export-helper root-block-uuids-or-page-name)))})
+                                       (reset! *content (export-helper root-block-uuids-or-page-uuid)))})
 
 
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
              "remove emphasis"]
              "remove emphasis"]
@@ -238,7 +238,7 @@
                           :on-change (fn [e]
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :tag)
                                        (state/update-export-block-text-remove-options! e :tag)
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
-                                       (reset! *content (export-helper root-block-uuids-or-page-name)))})
+                                       (reset! *content (export-helper root-block-uuids-or-page-uuid)))})
 
 
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
             [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
              "remove #tags"]]
              "remove #tags"]]
@@ -251,7 +251,7 @@
                                        (state/update-export-block-text-other-options!
                                        (state/update-export-block-text-other-options!
                                          :newline-after-block (boolean (util/echecked? e)))
                                          :newline-after-block (boolean (util/echecked? e)))
                                        (reset! *text-other-options (state/get-export-block-text-other-options))
                                        (reset! *text-other-options (state/get-export-block-text-other-options))
-                                       (reset! *content (export-helper root-block-uuids-or-page-name)))})
+                                       (reset! *content (export-helper root-block-uuids-or-page-uuid)))})
             [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
             [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
              "newline after block"]
              "newline after block"]
 
 
@@ -261,7 +261,7 @@
                           :on-change (fn [e]
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :property)
                                        (state/update-export-block-text-remove-options! e :property)
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
                                        (reset! *text-remove-options (state/get-export-block-text-remove-options))
-                                       (reset! *content (export-helper root-block-uuids-or-page-name)))})
+                                       (reset! *content (export-helper root-block-uuids-or-page-uuid)))})
             [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
             [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
              "remove properties"]]
              "remove properties"]]
 
 
@@ -276,7 +276,7 @@
                                  level (if (= "all" value) :all (util/safe-parse-int value))]
                                  level (if (= "all" value) :all (util/safe-parse-int value))]
                              (state/update-export-block-text-other-options! :keep-only-level<=N level)
                              (state/update-export-block-text-other-options! :keep-only-level<=N level)
                              (reset! *text-other-options (state/get-export-block-text-other-options))
                              (reset! *text-other-options (state/get-export-block-text-other-options))
-                             (reset! *content (export-helper root-block-uuids-or-page-name))))}
+                             (reset! *content (export-helper root-block-uuids-or-page-uuid))))}
              (for [n (cons "all" (range 1 10))]
              (for [n (cons "all" (range 1 10))]
                [:option {:key n :value n} n])]]]))
                [:option {:key n :value n} n])]]]))
 
 
@@ -290,8 +290,8 @@
                          (util/copy-to-clipboard! @*content :html (when (= tp :html) @*content)))
                          (util/copy-to-clipboard! @*content :html (when (= tp :html) @*content)))
                        (reset! *copied? true)))
                        (reset! *copied? true)))
          (ui/button (t :export-save-to-file)
          (ui/button (t :export-save-to-file)
-           :on-click #(let [file-name (if (string? root-block-uuids-or-page-name)
-                                        (-> (db/get-page root-block-uuids-or-page-name)
+           :on-click #(let [file-name (if (uuid? root-block-uuids-or-page-uuid)
+                                        (-> (db/get-page root-block-uuids-or-page-uuid)
                                           (util/get-page-original-name))
                                           (util/get-page-original-name))
                                         (t/now))]
                                         (t/now))]
                         (utils/saveToFile (js/Blob. [@*content]) (str "logseq_" file-name) (if (= tp :text) "txt" (name tp)))))])]]))
                         (utils/saveToFile (js/Blob. [@*content]) (str "logseq_" file-name) (if (= tp :text) "txt" (name tp)))))])]]))

+ 0 - 67
src/main/frontend/components/hierarchy.cljs

@@ -1,67 +0,0 @@
-(ns frontend.components.hierarchy
-  (:require [clojure.string :as string]
-            [frontend.components.block :as block]
-            [frontend.db :as db]
-            [frontend.db.model :as db-model]
-            [frontend.state :as state]
-            [logseq.graph-parser.text :as text]
-            [frontend.ui :as ui]
-            [medley.core :as medley]
-            [rum.core :as rum]
-            [frontend.util :as util]))
-
-(defn- get-relation
-  "Get all parent pages along the namespace hierarchy path.
-   If there're aliases, only use the first namespaced alias."
-  [page]
-  (when-let [page (or (text/get-nested-page-name page) page)]
-    (let [repo (state/get-current-repo)
-          aliases (db/get-page-alias-names repo page)
-          all-page-names (conj aliases page)]
-      (when-let [page (or (first (filter text/namespace-page? all-page-names))
-                          (when (:block/_namespace (db/entity [:block/name (util/page-name-sanity-lc page)]))
-                            page))]
-        (let [namespace-pages (db/get-namespace-pages repo page)
-              parent-routes (db-model/get-page-namespace-routes repo page)
-              pages (->> (concat namespace-pages parent-routes)
-                         (distinct)
-                         (sort-by :block/name)
-                         (map (fn [page]
-                                (or (:block/original-name page) (:block/name page))))
-                         (map #(string/split % "/")))
-              page-namespace (db-model/get-page-namespace repo page)
-              page-namespace (util/get-page-original-name page-namespace)]
-          (cond
-            (seq pages)
-            {:namespaces pages
-             :namespace-pages namespace-pages}
-
-            page-namespace
-            {:namespaces [(string/split page-namespace "/")]
-             :namespace-pages namespace-pages}
-
-            :else
-            nil))))))
-
-(rum/defc structures
-  [page]
-  (let [{:keys [namespaces]} (get-relation page)]
-    (when (seq namespaces)
-      [:div.page-hierarchy.mt-6
-       (ui/foldable
-        [:h2.font-bold.opacity-30 "Hierarchy"]
-        [:ul.namespaces {:style {:margin "12px 24px"}}
-         (for [namespace namespaces]
-           [:li.my-2
-            (->>
-             (for [[idx page] (medley/indexed namespace)]
-               (when (and (string? page) page)
-                 (let [full-page (->> (take (inc idx) namespace)
-                                      util/string-join-path)]
-                   (block/page-reference false
-                                         full-page
-                                         {}
-                                         page))))
-             (interpose [:span.mx-2.opacity-30 "/"]))])]
-        {:default-collapsed? false
-         :title-trigger? true})])))

+ 16 - 22
src/main/frontend/components/page.cljs

@@ -4,7 +4,6 @@
             [frontend.components.block :as component-block]
             [frontend.components.block :as component-block]
             [frontend.components.content :as content]
             [frontend.components.content :as content]
             [frontend.components.editor :as editor]
             [frontend.components.editor :as editor]
-            [frontend.components.hierarchy :as hierarchy]
             [frontend.components.plugins :as plugins]
             [frontend.components.plugins :as plugins]
             [frontend.components.query :as query]
             [frontend.components.query :as query]
             [frontend.components.reference :as reference]
             [frontend.components.reference :as reference]
@@ -235,13 +234,10 @@
 (rum/defc page-title-editor < rum/reactive
 (rum/defc page-title-editor < rum/reactive
   [page {:keys [*input-value *title-value *edit? untitled? page-name old-name whiteboard-page?]}]
   [page {:keys [*input-value *title-value *edit? untitled? page-name old-name whiteboard-page?]}]
   (let [input-ref (rum/create-ref)
   (let [input-ref (rum/create-ref)
-        title (:block/original-name page)
         collide? #(and (not= (util/page-name-sanity-lc page-name)
         collide? #(and (not= (util/page-name-sanity-lc page-name)
-                         (util/page-name-sanity-lc @*title-value))
-                    (db/page-exists? page-name)
-                    (db/page-exists? @*title-value))
-        rename-fn (fn [old-name new-name]
-                    (page-handler/rename! old-name new-name))
+                             (util/page-name-sanity-lc @*title-value))
+                       (db/page-exists? page-name)
+                       (db/page-exists? @*title-value))
         rollback-fn #(let [old-name (if untitled? "" old-name)]
         rollback-fn #(let [old-name (if untitled? "" old-name)]
                        (reset! *title-value old-name)
                        (reset! *title-value old-name)
                        (gobj/set (rum/deref input-ref) "value" old-name)
                        (gobj/set (rum/deref input-ref) "value" old-name)
@@ -269,8 +265,8 @@
 
 
                     :else
                     :else
                     (p/do!
                     (p/do!
-                      (rename-fn (or title page-name) @*title-value)
-                      (js/setTimeout #(reset! *edit? false) 100)))
+                     (page-handler/rename! (:block/uuid page) @*title-value)
+                     (js/setTimeout #(reset! *edit? false) 100)))
                   (util/stop e))]
                   (util/stop e))]
     [:input.edit-input.p-0.focus:outline-none.ring-none
     [:input.edit-input.p-0.focus:outline-none.ring-none
      {:type          "text"
      {:type          "text"
@@ -348,7 +344,8 @@
             {:class (when-not whiteboard-page? "title")
             {:class (when-not whiteboard-page? "title")
              :on-pointer-down (fn [e]
              :on-pointer-down (fn [e]
                                 (when (util/right-click? e)
                                 (when (util/right-click? e)
-                                  (state/set-state! :page-title/context {:page page-name})))
+                                  (state/set-state! :page-title/context {:page page-name
+                                                                         :page-entity page})))
              :on-click (fn [e]
              :on-click (fn [e]
                          (when-not (= (.-nodeName (.-target e)) "INPUT")
                          (when-not (= (.-nodeName (.-target e)) "INPUT")
                            (.preventDefault e)
                            (.preventDefault e)
@@ -553,19 +550,15 @@
                  (when page
                  (when page
                    [:div {:key "page-references"}
                    [:div {:key "page-references"}
                     (rum/with-key
                     (rum/with-key
-                      (reference/references route-page-name)
+                      (reference/references page)
                       (str route-page-name "-refs"))]))
                       (str route-page-name "-refs"))]))
 
 
                (when (contains? (:block/type page) "class")
                (when (contains? (:block/type page) "class")
                  (class-component/class-children page))
                  (class-component/class-children page))
 
 
-               (when-not block-or-whiteboard?
-                 (when (not journal?)
-                   (hierarchy/structures route-page-name)))
-
                (when-not (or block-or-whiteboard? sidebar? home?)
                (when-not (or block-or-whiteboard? sidebar? home?)
                  [:div {:key "page-unlinked-references"}
                  [:div {:key "page-unlinked-references"}
-                  (reference/unlinked-references route-page-name)])])))))))
+                  (reference/unlinked-references page)])])))))))
 
 
 (rum/defcs page < rum/static
 (rum/defcs page < rum/static
   [state option]
   [state option]
@@ -1041,20 +1034,21 @@
 
 
      [:div.pt-6.flex.justify-end.gap-4
      [:div.pt-6.flex.justify-end.gap-4
       (ui/button
       (ui/button
-        (t :cancel)
-        :theme :gray
-        :on-click close-fn)
+       (t :cancel)
+       :theme :gray
+       :on-click close-fn)
 
 
       (ui/button
       (ui/button
        (t :yes)
        (t :yes)
        :on-click (fn []
        :on-click (fn []
                    (close-fn)
                    (close-fn)
                    (let [failed-pages (atom [])]
                    (let [failed-pages (atom [])]
-                     (p/let [_ (p/all (map (fn [page-name]
-                                             (page-handler/<delete! page-name nil
+                     (p/let [_ (p/all (map (fn [page]
+                                             (page-handler/<delete! (:block/uuid page) nil
                                                                     {:error-handler
                                                                     {:error-handler
                                                                      (fn []
                                                                      (fn []
-                                                                       (swap! failed-pages conj page-name))})) (map :block/name pages)))]
+                                                                       (swap! failed-pages conj (:block/name page)))}))
+                                        pages))]
                        (if (seq @failed-pages)
                        (if (seq @failed-pages)
                          (notification/show! (t :all-pages/failed-to-delete-pages (string/join ", " (map pr-str @failed-pages)))
                          (notification/show! (t :all-pages/failed-to-delete-pages (string/join ", " (map pr-str @failed-pages)))
                                              :warning false)
                                              :warning false)

+ 19 - 23
src/main/frontend/components/page_menu.cljs

@@ -21,37 +21,33 @@
             [logseq.common.path :as path]))
             [logseq.common.path :as path]))
 
 
 (defn- delete-page!
 (defn- delete-page!
-  [page-name]
-  (page-handler/<delete! page-name
+  [page]
+  (page-handler/<delete! (:block/uuid page)
                         (fn []
                         (fn []
-                          (notification/show! (str "Page " page-name " was deleted successfully!")
+                          (notification/show! (str "Page " (:block/original-name page) " was deleted successfully!")
                                               :success))
                                               :success))
                         {:error-handler (fn [{:keys [msg]}]
                         {:error-handler (fn [{:keys [msg]}]
                                           (notification/show! msg :warning))})
                                           (notification/show! msg :warning))})
   (state/close-modal!))
   (state/close-modal!))
 
 
 (defn delete-page-confirm!
 (defn delete-page-confirm!
-  [page-name]
-  (when-not (string/blank? page-name)
+  [page]
+  (when page
     (-> (shui/dialog-confirm!
     (-> (shui/dialog-confirm!
-          {:title [:h3.text-lg.leading-6.font-medium.flex.gap-2.items-center
-                   [:span.top-1.relative
-                    (shui/tabler-icon "alert-triangle")]
-                   (if (config/db-based-graph? (state/get-current-repo))
-                     (t :page/db-delete-confirmation)
-                     (t :page/delete-confirmation))]
-           :content [:p.opacity-60 (str "- " page-name)]})
-      (p/then #(delete-page! page-name)))))
+         {:title [:h3.text-lg.leading-6.font-medium.flex.gap-2.items-center
+                  [:span.top-1.relative
+                   (shui/tabler-icon "alert-triangle")]
+                  (if (config/db-based-graph? (state/get-current-repo))
+                    (t :page/db-delete-confirmation)
+                    (t :page/delete-confirmation))]
+          :content [:p.opacity-60 (str "- " (:block/original-name page))]})
+        (p/then #(delete-page! page)))))
 
 
 (defn ^:large-vars/cleanup-todo page-menu
 (defn ^:large-vars/cleanup-todo page-menu
-  [page-name]
-  (when-let [page-name (or
-                        page-name
-                        (state/get-current-page)
-                        (state/get-current-whiteboard))]
-    (let [page-name (util/page-name-sanity-lc page-name)
+  [page]
+  (when page
+    (let [page-name (:block/name page)
           repo (state/sub :git/current-repo)
           repo (state/sub :git/current-repo)
-          page (db/entity repo [:block/name page-name])
           page-original-name (:block/original-name page)
           page-original-name (:block/original-name page)
           whiteboard? (contains? (set (:block/type page)) "whiteboard")
           whiteboard? (contains? (set (:block/type page)) "whiteboard")
           block? (and page (util/uuid-string? page-name) (not whiteboard?))
           block? (and page (util/uuid-string? page-name) (not whiteboard?))
@@ -68,7 +64,7 @@
                                     (file-sync-handler/current-graph-sync-on?)
                                     (file-sync-handler/current-graph-sync-on?)
                                     (file-sync-handler/get-current-graph-uuid))
                                     (file-sync-handler/get-current-graph-uuid))
           db-based? (config/db-based-graph? repo)]
           db-based? (config/db-based-graph? repo)]
-      (when (and page (not block?))
+      (when (not block?)
         (->>
         (->>
          [(when-not config/publishing?
          [(when-not config/publishing?
             {:title   (if favorited?
             {:title   (if favorited?
@@ -105,7 +101,7 @@
                         (and db-based?
                         (and db-based?
                              (:logseq.property/built-in? page)))
                              (:logseq.property/built-in? page)))
             {:title   (t :page/delete)
             {:title   (t :page/delete)
-             :options {:on-click #(delete-page-confirm! page-name)}})
+             :options {:on-click #(delete-page-confirm! page)}})
 
 
           (when (and (not (mobile-util/native-platform?))
           (when (and (not (mobile-util/native-platform?))
                      (state/get-current-page))
                      (state/get-current-page))
@@ -132,7 +128,7 @@
             {:title   (t :export-page)
             {:title   (t :export-page)
              :options {:on-click #(shui/dialog-open!
              :options {:on-click #(shui/dialog-open!
                                    (fn []
                                    (fn []
-                                     (export/export-blocks (:block/name page) {:whiteboard? whiteboard?}))
+                                     (export/export-blocks (:block/uuid page) {:whiteboard? whiteboard?}))
                                    {:class "w-auto md:max-w-4xl max-h-[80vh] overflow-y-auto"})}})
                                    {:class "w-auto md:max-w-4xl max-h-[80vh] overflow-y-auto"})}})
 
 
           (when (util/electron?)
           (when (util/electron?)

+ 2 - 1
src/main/frontend/components/property/value.cljs

@@ -269,7 +269,8 @@
                                    (let [repo (state/get-current-repo)
                                    (let [repo (state/get-current-repo)
                                          class-names (map #(:block/original-name (db/entity repo [:block/uuid %])) string-classes)
                                          class-names (map #(:block/original-name (db/entity repo [:block/uuid %])) string-classes)
                                          descendent-classes (->> class-names
                                          descendent-classes (->> class-names
-                                                                 (mapcat #(db/get-namespace-pages repo %))
+                                                                 ;; FIXME:
+                                                                 ;; (mapcat #(db/get-namespace-pages repo %))
                                                                  (map :block/original-name))]
                                                                  (map :block/original-name))]
                                      (->> (concat class-names descendent-classes)
                                      (->> (concat class-names descendent-classes)
                                           (filter #(string/includes? % class-input))
                                           (filter #(string/includes? % class-input))

+ 1 - 7
src/main/frontend/components/query/builder.cljs

@@ -156,12 +156,6 @@
         repo (state/get-current-repo)]
         repo (state/get-current-repo)]
     [:div
     [:div
      (case @*mode
      (case @*mode
-       "namespace"
-       (let [items (sort (db-model/get-all-namespace-parents repo))]
-         (select items
-                 (fn [{:keys [value]}]
-                   (append-tree! *tree opts loc [:namespace value]))))
-
        "tags"
        "tags"
        (let [items (->> (db-model/get-all-tagged-pages repo)
        (let [items (->> (db-model/get-all-tagged-pages repo)
                         (map second)
                         (map second)
@@ -330,7 +324,7 @@
       (str (name f) ": "
       (str (name f) ": "
            (string/join " | " (rest clause)))
            (string/join " | " (rest clause)))
 
 
-      (contains? #{:page :task :namespace} (keyword f))
+      (contains? #{:page :task} (keyword f))
       (str (name f) ": " (if (vector? (second clause))
       (str (name f) ": " (if (vector? (second clause))
                            (second (second clause))
                            (second (second clause))
                            (second clause)))
                            (second clause)))

+ 33 - 37
src/main/frontend/components/reference.cljs

@@ -107,9 +107,9 @@
     (when-not (state/sub-async-query-loading (str (:db/id e) "-refs"))
     (when-not (state/sub-async-query-loading (str (:db/id e) "-refs"))
       (let [page? (some? (:block/name e))
       (let [page? (some? (:block/name e))
             ref-blocks (if page?
             ref-blocks (if page?
-                         (-> (db/get-page-referenced-blocks (:block/name e))
+                         (-> (db/get-page-referenced-blocks (:db/id e))
                              db-utils/group-by-page)
                              db-utils/group-by-page)
-                         (db/get-block-referenced-blocks block-id))]
+                         (db/get-block-referenced-blocks (:db/id e)))]
         (when (> (count ref-blocks) 0)
         (when (> (count ref-blocks) 0)
           (let [ref-hiccup (block/->hiccup ref-blocks
           (let [ref-hiccup (block/->hiccup ref-blocks
                                            {:id (str block-id)
                                            {:id (str block-id)
@@ -188,37 +188,34 @@
             (conj result fb))))))))
             (conj result fb))))))))
 
 
 (rum/defc sub-page-properties-changed < rum/static
 (rum/defc sub-page-properties-changed < rum/static
-  [page-name v filters-atom]
+  [page-entity v filters-atom]
   (rum/use-effect!
   (rum/use-effect!
-    (fn []
-      (reset! filters-atom
-              (page-handler/get-filters (util/page-name-sanity-lc page-name))))
-    [page-name v filters-atom])
+   (fn []
+     (reset! filters-atom
+             (page-handler/get-filters page-entity)))
+   [page-entity v filters-atom])
   [:<>])
   [:<>])
 
 
 (rum/defcs references* < rum/reactive db-mixins/query
 (rum/defcs references* < rum/reactive db-mixins/query
   (rum/local nil ::ref-pages)
   (rum/local nil ::ref-pages)
   {:init (fn [state]
   {:init (fn [state]
-           (let [page-name (->> (first (:rum/args state))
-                                util/page-name-sanity-lc)
-                 page (db/entity [:block/name page-name])
-                 filters (when page-name (atom nil))]
+           (let [page (first (:rum/args state))
+                 filters (when page (atom nil))]
              (when page (db-async/<get-block-refs (state/get-current-repo) (:db/id page)))
              (when page (db-async/<get-block-refs (state/get-current-repo) (:db/id page)))
              (assoc state ::filters filters)))}
              (assoc state ::filters filters)))}
-  [state page-name]
-  (when page-name
-    (let [repo (state/get-current-repo)
-          page-name (util/page-name-sanity-lc page-name)
-          page-entity (db/entity repo [:block/name page-name])]
+  [state page-entity]
+  (when page-entity
+    (let [repo (state/get-current-repo)]
       (when page-entity
       (when page-entity
         (when-not (state/sub-async-query-loading (str (:db/id page-entity) "-refs"))
         (when-not (state/sub-async-query-loading (str (:db/id page-entity) "-refs"))
-          (let [page-props-v (state/sub-page-properties-changed page-name)
+          (let [page-name (:block/name page-entity)
+                page-props-v (state/sub-page-properties-changed page-name)
                 *ref-pages (::ref-pages state)
                 *ref-pages (::ref-pages state)
                 filters-atom (get state ::filters)
                 filters-atom (get state ::filters)
                 filter-state (rum/react filters-atom)
                 filter-state (rum/react filters-atom)
-                ref-blocks (db/get-page-referenced-blocks page-name)
                 page-id (:db/id page-entity)
                 page-id (:db/id page-entity)
-                aliases (db/page-alias-set repo page-name)
+                ref-blocks (db/get-page-referenced-blocks page-id)
+                aliases (db/page-alias-set repo page-id)
                 aliases-exclude-self (set (remove #{page-id} aliases))
                 aliases-exclude-self (set (remove #{page-id} aliases))
                 top-level-blocks (filter (fn [b] (some aliases (set (map :db/id (:block/refs b))))) ref-blocks)
                 top-level-blocks (filter (fn [b] (some aliases (set (map :db/id (:block/refs b))))) ref-blocks)
                 top-level-blocks-ids (set (map :db/id top-level-blocks))
                 top-level-blocks-ids (set (map :db/id top-level-blocks))
@@ -255,51 +252,50 @@
             (reset! *ref-pages ref-pages)
             (reset! *ref-pages ref-pages)
             (when (or (seq filter-state) (> filter-n 0))
             (when (or (seq filter-state) (> filter-n 0))
               [:div.references.page-linked.flex-1.flex-row
               [:div.references.page-linked.flex-1.flex-row
-               (sub-page-properties-changed page-name page-props-v filters-atom)
+               (sub-page-properties-changed page-entity page-props-v filters-atom)
                [:div.content.pt-6
                [:div.content.pt-6
                 (references-cp page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
                 (references-cp page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
 
 
 (rum/defc references
 (rum/defc references
-  [page-name]
+  [page-entity]
   (ui/catch-error
   (ui/catch-error
    (ui/component-error (if (config/db-based-graph? (state/get-current-repo))
    (ui/component-error (if (config/db-based-graph? (state/get-current-repo))
                          "Linked References: Unexpected error."
                          "Linked References: Unexpected error."
                          "Linked References: Unexpected error. Please re-index your graph first."))
                          "Linked References: Unexpected error. Please re-index your graph first."))
-   (references* page-name)))
+   (references* page-entity)))
 
 
 (rum/defcs unlinked-references-aux
 (rum/defcs unlinked-references-aux
   < rum/reactive db-mixins/query
   < rum/reactive db-mixins/query
   {:init
   {:init
    (fn [state]
    (fn [state]
      (let [*result (atom nil)
      (let [*result (atom nil)
-           [page-name *n-ref] (:rum/args state)]
-       (p/let [result (search/get-page-unlinked-refs page-name)]
+           [page *n-ref] (:rum/args state)]
+       (p/let [result (search/get-page-unlinked-refs (:db/id page))]
          (reset! *n-ref (count result))
          (reset! *n-ref (count result))
          (reset! *result result))
          (reset! *result result))
        (assoc state ::result *result)))}
        (assoc state ::result *result)))}
-  [state page-name _n-ref]
+  [state page _n-ref]
   (let [ref-blocks (rum/react (::result state))]
   (let [ref-blocks (rum/react (::result state))]
     (when (seq ref-blocks)
     (when (seq ref-blocks)
       [:div.references-blocks
       [:div.references-blocks
        (let [ref-hiccup (block/->hiccup ref-blocks
        (let [ref-hiccup (block/->hiccup ref-blocks
-                                        {:id (str page-name "-unlinked-")
+                                        {:id (str (:block/original-name page) "-unlinked-")
                                          :ref? true
                                          :ref? true
                                          :group-by-page? true
                                          :group-by-page? true
                                          :editor-box editor/box}
                                          :editor-box editor/box}
                                         {})]
                                         {})]
-         (content/content page-name
+         (content/content (:block/name page)
                           {:hiccup ref-hiccup}))])))
                           {:hiccup ref-hiccup}))])))
 
 
 (rum/defcs unlinked-references < rum/reactive
 (rum/defcs unlinked-references < rum/reactive
   (rum/local nil ::n-ref)
   (rum/local nil ::n-ref)
-  [state page-name]
+  [state page]
   (let [n-ref (get state ::n-ref)]
   (let [n-ref (get state ::n-ref)]
-    (when page-name
-      (let [page-name (string/lower-case page-name)]
-        [:div.references.page-unlinked.mt-6.flex-1.flex-row.faster-fade-in
-         [:div.content.flex-1
-          (ui/foldable
-           [:h2.font-medium (t :unlinked-references/reference-count @n-ref)]
-           (fn [] (unlinked-references-aux page-name n-ref))
-           {:default-collapsed? true
-            :title-trigger? true})]]))))
+    (when page
+      [:div.references.page-unlinked.mt-6.flex-1.flex-row.faster-fade-in
+       [:div.content.flex-1
+        (ui/foldable
+         [:h2.font-medium (t :unlinked-references/reference-count @n-ref)]
+         (fn [] (unlinked-references-aux page n-ref))
+         {:default-collapsed? true
+          :title-trigger? true})]])))

+ 1 - 1
src/main/frontend/components/right_sidebar.cljs

@@ -264,7 +264,7 @@
               {:class         (when collapsed? "rounded-b-md")
               {:class         (when collapsed? "rounded-b-md")
                :draggable     true
                :draggable     true
                :on-drag-start (fn [event]
                :on-drag-start (fn [event]
-                                (editor-handler/block->data-transfer! (:block/name (db/entity db-id)) event)
+                                (editor-handler/block->data-transfer! (:block/name (db/entity db-id)) event true)
                                 (reset! *drag-from idx))
                                 (reset! *drag-from idx))
                :on-drag-end   (fn [_event]
                :on-drag-end   (fn [_event]
                                 (when drag-to (state/sidebar-move-block! idx drag-to))
                                 (when drag-to (state/sidebar-move-block! idx drag-to))

+ 15 - 12
src/main/frontend/components/whiteboard.cljs

@@ -21,7 +21,9 @@
             [rum.core :as rum]
             [rum.core :as rum]
             [shadow.loader :as loader]
             [shadow.loader :as loader]
             [frontend.config :as config]
             [frontend.config :as config]
-            [frontend.db.async :as db-async]))
+            [frontend.db.async :as db-async]
+            [logseq.common.util :as common-util]
+            [frontend.db :as db]))
 
 
 (defonce tldraw-loaded? (atom false))
 (defonce tldraw-loaded? (atom false))
 (rum/defc tldraw-app < rum/reactive
 (rum/defc tldraw-app < rum/reactive
@@ -160,7 +162,7 @@
       (util/stop e)
       (util/stop e)
       (if show-checked?
       (if show-checked?
         (on-checked-change (not checked))
         (on-checked-change (not checked))
-        (route-handler/redirect-to-whiteboard! page-name)))}
+        (route-handler/redirect-to-page! page-name)))}
    [:div.dashboard-card-title
    [:div.dashboard-card-title
     [:div.flex.w-full.items-center
     [:div.flex.w-full.items-center
      [:div.dashboard-card-title-name.font-bold
      [:div.dashboard-card-title-name.font-bold
@@ -248,12 +250,12 @@
     [:div "This feature is not publicly available yet."]))
     [:div "This feature is not publicly available yet."]))
 
 
 (rum/defc whiteboard-page
 (rum/defc whiteboard-page
-  [page-name block-id]
-  (let [[ref bp] (use-breakpoint)]
+  [page-uuid block-id]
+  (let [[ref bp] (use-breakpoint)
+        page (db/entity [:block/uuid page-uuid])]
     [:div.absolute.w-full.h-full.whiteboard-page
     [:div.absolute.w-full.h-full.whiteboard-page
-
      ;; makes sure the whiteboard will not cover the borders
      ;; makes sure the whiteboard will not cover the borders
-     {:key page-name
+     {:key (str page-uuid)
       :ref ref
       :ref ref
       :data-breakpoint (name bp)
       :data-breakpoint (name bp)
       :style {:padding "0.5px" :z-index 0
       :style {:padding "0.5px" :z-index 0
@@ -270,26 +272,27 @@
                            (util/stop e)
                            (util/stop e)
                            (common-handler/show-custom-context-menu!
                            (common-handler/show-custom-context-menu!
                             e
                             e
-                            (content/page-title-custom-context-menu-content page-name))
+                            (content/page-title-custom-context-menu-content page))
                            (state/set-state! :page-title/context nil))}
                            (state/set-state! :page-title/context nil))}
-       (page/page-title page-name {:*hover? (atom false)})]
+       (page/page-title (:block/original-name page) {:*hover? (atom false)})]
 
 
       [:div.whiteboard-page-refs
       [:div.whiteboard-page-refs
-       (references-count page-name
+       (references-count (:block/original-name page)
                          "text-md px-3 py-2 cursor-default whiteboard-page-refs-count"
                          "text-md px-3 py-2 cursor-default whiteboard-page-refs-count"
                          {:hover? true
                          {:hover? true
                           :render-fn (fn [open? refs-count] [:span.whiteboard-page-refs-count-label
                           :render-fn (fn [open? refs-count] [:span.whiteboard-page-refs-count-label
                                                              (t :whiteboard/reference-count refs-count)
                                                              (t :whiteboard/reference-count refs-count)
                                                              (ui/icon (if open? "references-hide" "references-show")
                                                              (ui/icon (if open? "references-hide" "references-show")
                                                                       {:extension? true})])})]]
                                                                       {:extension? true})])})]]
-     (tldraw-app page-name block-id)]))
+     (tldraw-app (:block/original-name page) block-id)]))
 
 
 (rum/defc whiteboard-route <
 (rum/defc whiteboard-route <
   (shortcut/mixin :shortcut.handler/whiteboard false)
   (shortcut/mixin :shortcut.handler/whiteboard false)
   [route-match]
   [route-match]
-  (let [name (get-in route-match [:parameters :path :name])
+  (let [page-uuid-str (get-in route-match [:parameters :path :name])
         {:keys [block-id]} (get-in route-match [:parameters :query])]
         {:keys [block-id]} (get-in route-match [:parameters :query])]
-    (whiteboard-page name block-id)))
+    (when (common-util/uuid-string? page-uuid-str)
+      (whiteboard-page (uuid page-uuid-str) block-id))))
 
 
 (rum/defc onboarding-welcome
 (rum/defc onboarding-welcome
   [close-fn]
   [close-fn]

+ 2 - 2
src/main/frontend/db.cljs

@@ -35,12 +35,12 @@
   get-file-last-modified-at get-file get-file-page get-file-page-id file-exists?
   get-file-last-modified-at get-file get-file-page get-file-page-id file-exists?
   get-files-blocks get-files-full get-journals-length get-pages-with-file
   get-files-blocks get-files-full get-journals-length get-pages-with-file
   get-latest-journals get-page get-page-alias get-page-alias-names
   get-latest-journals get-page get-page-alias get-page-alias-names
-  get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-properties
+  get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format
   get-page-referenced-blocks get-page-referenced-blocks-full get-page-referenced-pages
   get-page-referenced-blocks get-page-referenced-blocks-full get-page-referenced-pages
   get-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   get-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   journal-page? page-alias-set sub-block
   journal-page? page-alias-set sub-block
   set-file-last-modified-at! page-empty? page-exists? get-alias-source-page
   set-file-last-modified-at! page-empty? page-exists? get-alias-source-page
-  set-file-content! has-children? get-namespace-pages get-all-namespace-relation]
+  set-file-content! has-children?]
 
 
  [frontend.db.react
  [frontend.db.react
   get-current-page set-key-value
   get-current-page set-key-value

+ 5 - 14
src/main/frontend/db/async.cljs

@@ -3,7 +3,6 @@
   (:require [promesa.core :as p]
   (:require [promesa.core :as p]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.config :as config]
             [frontend.config :as config]
-            [frontend.util :as util]
             [frontend.db.utils :as db-utils]
             [frontend.db.utils :as db-utils]
             [frontend.db.async.util :as db-async-util]
             [frontend.db.async.util :as db-async-util]
             [frontend.db.file-based.async :as file-async]
             [frontend.db.file-based.async :as file-async]
@@ -16,7 +15,8 @@
             [cljs-time.core :as t]
             [cljs-time.core :as t]
             [cljs-time.format :as tf]
             [cljs-time.format :as tf]
             [logseq.db :as ldb]
             [logseq.db :as ldb]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [frontend.util :as util]))
 
 
 (def <q db-async-util/<q)
 (def <q db-async-util/<q)
 (def <pull db-async-util/<pull)
 (def <pull db-async-util/<pull)
@@ -70,16 +70,6 @@
         (map :block/original-name properties))
         (map :block/original-name properties))
       (file-async/<file-based-get-all-properties graph))))
       (file-async/<file-based-get-all-properties graph))))
 
 
-(comment
-  (defn <get-pages
-    [graph]
-    (p/let [result (<q graph
-                       '[:find [?page-original-name ...]
-                         :where
-                         [?page :block/name ?page-name]
-                         [(get-else $ ?page :block/original-name ?page-name) ?page-original-name]])]
-      (remove db-model/hidden-page? result))))
-
 (defn <get-property-values
 (defn <get-property-values
   [graph property]
   [graph property]
   (when-not (config/db-based-graph? graph)
   (when-not (config/db-based-graph? graph)
@@ -106,12 +96,13 @@
             (util/uuid-string? name')
             (util/uuid-string? name')
             (db/entity [:block/uuid (uuid name')])
             (db/entity [:block/uuid (uuid name')])
             :else
             :else
-            (db/entity [:block/name (util/page-name-sanity-lc name')]))]
+            (db/entity (ldb/get-first-page-by-name (db/get-db) name')))
+        uuid-str (or (str (:block/uuid e)) name')]
     (if (:block.temp/fully-loaded? e)
     (if (:block.temp/fully-loaded? e)
       e
       e
       (when-let [^Object sqlite @db-browser/*worker]
       (when-let [^Object sqlite @db-browser/*worker]
         (state/update-state! :db/async-queries (fn [s] (conj s name')))
         (state/update-state! :db/async-queries (fn [s] (conj s name')))
-        (p/let [result (.get-block-and-children sqlite graph name' children?)
+        (p/let [result (.get-block-and-children sqlite graph uuid-str children?)
                 {:keys [block children] :as result'} (ldb/read-transit-str result)
                 {:keys [block children] :as result'} (ldb/read-transit-str result)
                 conn (db/get-db graph false)
                 conn (db/get-db graph false)
                 block-and-children (cons block children)
                 block-and-children (cons block children)

+ 1 - 2
src/main/frontend/db/debug.cljs

@@ -33,8 +33,7 @@
    (concat
    (concat
     [(:block/parent block)
     [(:block/parent block)
      (:block/left block)
      (:block/left block)
-     (:block/page block)
-     (:block/namespace block)]
+     (:block/page block)]
     (:block/tags block)
     (:block/tags block)
     (:block/alias block)
     (:block/alias block)
     (:block/refs block)
     (:block/refs block)

+ 94 - 218
src/main/frontend/db/model.cljs

@@ -15,7 +15,6 @@
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.content :as db-content]
             [logseq.db.frontend.content :as db-content]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
-            [logseq.graph-parser.text :as text]
             [logseq.graph-parser.db :as gp-db]
             [logseq.graph-parser.db :as gp-db]
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
             [logseq.common.util.date-time :as date-time-util]
             [logseq.common.util.date-time :as date-time-util]
@@ -53,20 +52,6 @@
          [?page :block/name ?page-name]]
          [?page :block/name ?page-name]]
        (conn/get-db repo)))
        (conn/get-db repo)))
 
 
-(defn get-all-namespace-relation
-  [repo]
-  (d/q '[:find ?page-name ?parent
-         :where
-         [?page :block/name ?page-name]
-         [?page :block/namespace ?e]
-         [?e :block/original-name ?parent]]
-    (conn/get-db repo)))
-
-(defn get-all-namespace-parents
-  [repo]
-  (->> (get-all-namespace-relation repo)
-       (map second)))
-
 (def hidden-page? ldb/hidden-page?)
 (def hidden-page? ldb/hidden-page?)
 
 
 (defn get-all-pages
 (defn get-all-pages
@@ -247,24 +232,25 @@ independent of format as format specific heading characters are stripped"
 (defn get-page-format
 (defn get-page-format
   [page-name]
   [page-name]
   {:post [(keyword? %)]}
   {:post [(keyword? %)]}
-  (keyword
-   (or
-    (let [page (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page-name)])]
-      (or
-       (:block/format page)
-       (when-let [file (:block/file page)]
-         (when-let [path (:file/path (db-utils/entity (:db/id file)))]
-           (common-util/get-format path)))))
-    (state/get-preferred-format)
-    :markdown)))
+  (if (config/db-based-graph? (state/get-current-repo))
+    :markdown
+    (keyword
+     (or
+      (let [page (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page-name))]
+        (or
+         (:block/format page)
+         (when-let [file (:block/file page)]
+           (when-let [path (:file/path (db-utils/entity (:db/id file)))]
+             (common-util/get-format path)))))
+      (state/get-preferred-format)
+      :markdown))))
 
 
 (defn page-alias-set
 (defn page-alias-set
-  [repo-url page]
-  (when-let [page-id (:db/id (db-utils/entity repo-url [:block/name (util/safe-page-name-sanity-lc page)]))]
-    (->>
-     (ldb/get-page-alias (conn/get-db repo-url) page-id)
-     (set)
-     (set/union #{page-id}))))
+  [repo-url page-id]
+  (->>
+   (ldb/get-page-alias (conn/get-db repo-url) page-id)
+   (set)
+   (set/union #{page-id})))
 
 
 (defn get-page-names-by-ids
 (defn get-page-names-by-ids
   ([ids]
   ([ids]
@@ -276,19 +262,12 @@ independent of format as format specific heading characters are stripped"
             (map :block/name))))))
             (map :block/name))))))
 
 
 (defn get-page-alias-names
 (defn get-page-alias-names
-  [repo page-name]
-  (let [alias-ids (->> (page-alias-set repo page-name)
-                       (remove nil?))]
+  [repo page-id]
+  (let [page (db-utils/entity page-id)
+        alias-ids (->> (page-alias-set repo page-id)
+                       (remove #{page-id}))]
     (when (seq alias-ids)
     (when (seq alias-ids)
-      (let [names (->> (get-page-names-by-ids repo alias-ids)
-                       (remove nil?)
-                       distinct
-                       (remove #(= (util/page-name-sanity-lc %) (util/page-name-sanity-lc page-name))))
-            lookup-refs (map (fn [name]
-                               [:block/name (util/page-name-sanity-lc name)]) names)]
-        (->> (db-utils/pull-many repo '[:block/name :block/original-name] lookup-refs)
-             (map (fn [m]
-                    (or (:block/original-name m) (:block/name m)))))))))
+      (map (fn [id] (:block/original-name (db-utils/entity id))) alias-ids))))
 
 
 (defn with-pages
 (defn with-pages
   [blocks]
   [blocks]
@@ -304,11 +283,6 @@ independent of format as format specific heading characters are stripped"
                 blocks)]
                 blocks)]
     blocks))
     blocks))
 
 
-(defn get-page-properties
-  [page]
-  (when-let [page (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)])]
-    (:block/properties page)))
-
 (def sort-by-left ldb/sort-by-left)
 (def sort-by-left ldb/sort-by-left)
 
 
 (defn sub-block
 (defn sub-block
@@ -335,6 +309,7 @@ independent of format as format specific heading characters are stripped"
                      f))
                      f))
                  form))
                  form))
 
 
+;; File-based only
 ;; Diverged of get-sorted-page-block-ids
 ;; Diverged of get-sorted-page-block-ids
 (defn get-sorted-page-block-ids-and-levels
 (defn get-sorted-page-block-ids-and-levels
   "page-name: the page name, original name
   "page-name: the page name, original name
@@ -343,8 +318,7 @@ independent of format as format specific heading characters are stripped"
        :level - the level of the block, 1 for root, 2 for children of root, etc."
        :level - the level of the block, 1 for root, 2 for children of root, etc."
   [page-name]
   [page-name]
   {:pre [(string? page-name)]}
   {:pre [(string? page-name)]}
-  (let [sanitized-page (common-util/page-name-sanity-lc page-name)
-        page-id (:db/id (db-utils/entity [:block/name sanitized-page]))
+  (let [page-id (ldb/get-first-page-by-name (conn/get-db) page-name)
         root (db-utils/entity page-id)]
         root (db-utils/entity page-id)]
     (loop [result []
     (loop [result []
            children (sort-by-left (:block/_parent root) root)
            children (sort-by-left (:block/_parent root) root)
@@ -424,6 +398,8 @@ independent of format as format specific heading characters are stripped"
         (let [parent-id (:db/id (:block/parent (db-utils/entity db db-id)))]
         (let [parent-id (:db/id (:block/parent (db-utils/entity db db-id)))]
           (get-next db parent-id (assoc opts :init? false))))))
           (get-next db parent-id (assoc opts :init? false))))))
 
 
+(def page? ldb/page?)
+
 (defn get-prev
 (defn get-prev
   "Get prev block, either its left sibling if the sibling is collapsed or no children,
   "Get prev block, either its left sibling if the sibling is collapsed or no children,
   or get sibling's last deep displayable child (collaspsed parent or non-collapsed child)."
   or get sibling's last deep displayable child (collaspsed parent or non-collapsed child)."
@@ -437,17 +413,17 @@ independent of format as format specific heading characters are stripped"
          (some->> (get-block-deep-last-open-child-id db (:db/id prev-sibling))
          (some->> (get-block-deep-last-open-child-id db (:db/id prev-sibling))
                   (db-utils/entity db))))
                   (db-utils/entity db))))
      (let [parent (:block/parent entity)]
      (let [parent (:block/parent entity)]
-       (when-not (:block/name parent)
+       (when-not (page? parent)
          parent)))))
          parent)))))
 
 
 (defn get-page-blocks-no-cache
 (defn get-page-blocks-no-cache
-  ([page]
-   (get-page-blocks-no-cache (state/get-current-repo) page nil))
-  ([repo page]
-   (get-page-blocks-no-cache repo page nil))
-  ([repo page opts]
+  ([page-id]
+   (get-page-blocks-no-cache (state/get-current-repo) page-id nil))
+  ([repo page-id]
+   (get-page-blocks-no-cache repo page-id nil))
+  ([repo page-id opts]
    (when-let [db (conn/get-db repo)]
    (when-let [db (conn/get-db repo)]
-     (ldb/get-page-blocks db page opts))))
+     (ldb/get-page-blocks db page-id opts))))
 
 
 (defn get-page-blocks-count
 (defn get-page-blocks-count
   [repo page-id]
   [repo page-id]
@@ -558,8 +534,9 @@ independent of format as format specific heading characters are stripped"
   (if-let [id (if (uuid? page-name) page-name
   (if-let [id (if (uuid? page-name) page-name
                   (parse-uuid page-name))]
                   (parse-uuid page-name))]
     (db-utils/entity [:block/uuid id])
     (db-utils/entity [:block/uuid id])
-    (db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])))
+    (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) (str page-name)))))
 
 
+;; FIXME: should pass page's db id
 (defn get-redirect-page-name
 (defn get-redirect-page-name
   "Given any readable page-name, return the exact page-name in db. If page
   "Given any readable page-name, return the exact page-name in db. If page
    doesn't exists yet, will return the passed `page-name`. Accepts both
    doesn't exists yet, will return the passed `page-name`. Accepts both
@@ -569,7 +546,7 @@ independent of format as format specific heading characters are stripped"
   ([page-name alias?]
   ([page-name alias?]
    (when page-name
    (when page-name
      (let [page-name' (util/page-name-sanity-lc page-name)
      (let [page-name' (util/page-name-sanity-lc page-name)
-           page-entity (db-utils/entity [:block/name page-name'])]
+           page-entity (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page-name))]
        (cond
        (cond
          alias?
          alias?
          page-name'
          page-name'
@@ -584,10 +561,11 @@ independent of format as format specific heading characters are stripped"
            (or (when source-page (:block/name source-page))
            (or (when source-page (:block/name source-page))
                page-name')))))))
                page-name')))))))
 
 
+;; FIXME: should pass page's db id
 (defn get-page-original-name
 (defn get-page-original-name
   [page-name]
   [page-name]
   (when (string? page-name)
   (when (string? page-name)
-    (let [page (db-utils/pull [:block/name (util/page-name-sanity-lc page-name)])]
+    (let [page (ldb/get-first-page-by-name (conn/get-db) page-name)]
       (or (:block/original-name page)
       (or (:block/original-name page)
           (:block/name page)))))
           (:block/name page)))))
 
 
@@ -603,6 +581,7 @@ independent of format as format specific heading characters are stripped"
          (conn/get-db (state/get-current-repo))
          (conn/get-db (state/get-current-repo))
          today)))
          today)))
 
 
+;; FIXME: [?page :block/type "journal"]
 (defn get-latest-journals
 (defn get-latest-journals
   ([n]
   ([n]
    (get-latest-journals (state/get-current-repo) n))
    (get-latest-journals (state/get-current-repo) n))
@@ -628,13 +607,11 @@ independent of format as format specific heading characters are stripped"
 
 
 ;; get pages that this page referenced
 ;; get pages that this page referenced
 (defn get-page-referenced-pages
 (defn get-page-referenced-pages
-  [repo page]
+  [repo page-id]
   (when-let [db (conn/get-db repo)]
   (when-let [db (conn/get-db repo)]
-    (let [page-name (util/safe-page-name-sanity-lc page)
-          pages (page-alias-set repo page)
-          page-id (:db/id (db-utils/entity [:block/name page-name]))
+    (let [pages (page-alias-set repo page-id)
           ref-pages (d/q
           ref-pages (d/q
-                     '[:find [?ref-page-name ...]
+                     '[:find [?ref-page ?ref-page-name]
                        :in $ ?pages
                        :in $ ?pages
                        :where
                        :where
                        [(untuple ?pages) [?page ...]]
                        [(untuple ?pages) [?page ...]]
@@ -643,52 +620,7 @@ independent of format as format specific heading characters are stripped"
                        [?ref-page :block/name ?ref-page-name]]
                        [?ref-page :block/name ?ref-page-name]]
                      db
                      db
                      pages)]
                      pages)]
-      (mapv (fn [page] [page (get-page-alias repo page)]) ref-pages))))
-
-(def ns-char "/")
-(def ns-re #"/")
-
-(defn- get-parents-namespace-list
-  "Return list of parents namespace"
-  [page-namespace & nested-found]
-  (if (text/namespace-page? page-namespace)
-    (let [pre-nested-vec (drop-last (string/split page-namespace ns-re))
-          my-nested-found (if (nil? nested-found)
-                            []
-                            nested-found)]
-      (if (= (count pre-nested-vec) 1)
-        (conj my-nested-found (nth pre-nested-vec 0))
-        (let [pre-nested-str (string/join ns-char pre-nested-vec)]
-          (recur pre-nested-str (conj my-nested-found pre-nested-str)))))
-    []))
-
-(defn- get-unnecessary-namespaces-name
-  "Return unnecessary namespace from a list of page's name"
-  [pages-list]
-  (->> pages-list
-       (remove nil?)
-       (mapcat get-parents-namespace-list)
-       distinct))
-
-(defn- remove-nested-namespaces-link
-  "Remove relations between pages and their nested namespace"
-  [pages-relations]
-  (let [pages-relations-to-return (distinct (mapcat
-                                             identity
-                                             (for [item (for [a-link-from (mapv (fn [a-rel] (first a-rel)) pages-relations)]
-                                                          [a-link-from (mapv
-                                                                        (fn [a-rel] (second a-rel))
-                                                                        (filterv
-                                                                         (fn [link-target] (=  a-link-from (first link-target)))
-                                                                         pages-relations))])
-                                                   :let [list-to (get item 1)
-                                                         page (get item 0)
-                                                         namespaces-to-remove (get-unnecessary-namespaces-name list-to)
-                                                         list-to-without-nested-ns (filterv (fn [elem] (not (some #{elem} namespaces-to-remove))) list-to)
-                                                         node-links (for [item-ok list-to-without-nested-ns]
-                                                                      [page item-ok])]]
-                                               (seq node-links))))]
-    pages-relations-to-return))
+      (mapv (fn [[ref-page ref-page-name]] [ref-page-name (get-page-alias repo ref-page)]) ref-pages))))
 
 
 ;; Ignore files with empty blocks for now
 ;; Ignore files with empty blocks for now
 (defn get-pages-relation
 (defn get-pages-relation
@@ -711,18 +643,16 @@ independent of format as format specific heading characters are stripped"
       (->>
       (->>
        (d/q q db)
        (d/q q db)
        (map (fn [[page ref-page-name]]
        (map (fn [[page ref-page-name]]
-              [page ref-page-name]))
-       (remove-nested-namespaces-link)))))
+              [page ref-page-name]))))))
 
 
 ;; get pages who mentioned this page
 ;; get pages who mentioned this page
 ;; TODO: use :block/_refs
 ;; TODO: use :block/_refs
 (defn get-pages-that-mentioned-page
 (defn get-pages-that-mentioned-page
-  [repo page include-journals]
+  [repo page-id include-journals]
   (when (conn/get-db repo)
   (when (conn/get-db repo)
-    (let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)]))
-          pages (page-alias-set repo page)
+    (let [pages (page-alias-set repo page-id)
           query-base '[:find ?mentioned-page-name
           query-base '[:find ?mentioned-page-name
-                       :in $ ?pages ?page-name
+                       :in $ ?pages
                        :where
                        :where
                        [?block :block/refs ?p]
                        [?block :block/refs ?p]
                        [(contains? ?pages ?p)]
                        [(contains? ?pages ?p)]
@@ -734,32 +664,30 @@ independent of format as format specific heading characters are stripped"
 
 
           mentioned-pages (->> (react/q repo [:frontend.worker.react/page<-pages page-id] {:use-cache? false}
           mentioned-pages (->> (react/q repo [:frontend.worker.react/page<-pages page-id] {:use-cache? false}
                                         query
                                         query
-                                        pages
-                                        page)
+                                        pages)
                                react
                                react
                                db-utils/seq-flatten)]
                                db-utils/seq-flatten)]
       (mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
       (mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
 
 
 (defn get-page-referenced-blocks-full
 (defn get-page-referenced-blocks-full
-  ([page]
-   (get-page-referenced-blocks-full (state/get-current-repo) page nil))
-  ([page options]
-   (get-page-referenced-blocks-full (state/get-current-repo) page options))
-  ([repo page options]
-   (when repo
+  ([page-id]
+   (get-page-referenced-blocks-full (state/get-current-repo) page-id nil))
+  ([page-id options]
+   (get-page-referenced-blocks-full (state/get-current-repo) page-id options))
+  ([repo page-id options]
+   (when (and repo page-id)
      (when-let [db (conn/get-db repo)]
      (when-let [db (conn/get-db repo)]
-       (let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)]))
-             pages (page-alias-set repo page)
+       (let [pages (page-alias-set repo page-id)
              aliases (set/difference pages #{page-id})]
              aliases (set/difference pages #{page-id})]
          (->>
          (->>
           (d/q
           (d/q
-            '[:find [(pull ?block ?block-attrs) ...]
-              :in $ [?ref-page ...] ?block-attrs
-              :where
-              [?block :block/path-refs ?ref-page]]
-            db
-            pages
-            (butlast block-attrs))
+           '[:find [(pull ?block ?block-attrs) ...]
+             :in $ [?ref-page ...] ?block-attrs
+             :where
+             [?block :block/path-refs ?ref-page]]
+           db
+           pages
+           (butlast block-attrs))
           (remove (fn [block] (= page-id (:db/id (:block/page block)))))
           (remove (fn [block] (= page-id (:db/id (:block/page block)))))
           db-utils/group-by-page
           db-utils/group-by-page
           (map (fn [[k blocks]]
           (map (fn [[k blocks]]
@@ -769,15 +697,14 @@ independent of format as format specific heading characters are stripped"
                    [k blocks])))))))))
                    [k blocks])))))))))
 
 
 (defn get-page-referenced-blocks
 (defn get-page-referenced-blocks
-  ([page]
-   (get-page-referenced-blocks (state/get-current-repo) page nil))
-  ([page options]
-   (get-page-referenced-blocks (state/get-current-repo) page options))
-  ([repo page options]
+  ([page-id]
+   (get-page-referenced-blocks (state/get-current-repo) page-id nil))
+  ([page-id options]
+   (get-page-referenced-blocks (state/get-current-repo) page-id options))
+  ([repo page-id options]
    (when repo
    (when repo
      (when (conn/get-db repo)
      (when (conn/get-db repo)
-       (let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)]))
-             pages (page-alias-set repo page)]
+       (let [pages (page-alias-set repo page-id)]
          (->>
          (->>
           (react/q repo
           (react/q repo
                    [:frontend.worker.react/refs page-id]
                    [:frontend.worker.react/refs page-id]
@@ -798,23 +725,23 @@ independent of format as format specific heading characters are stripped"
                     (= page-id (:db/id (:block/page block)))))
                     (= page-id (:db/id (:block/page block)))))
           (util/distinct-by :db/id)))))))
           (util/distinct-by :db/id)))))))
 
 
+;; TODO: no need to use datalog query, `:block/_refs`
 (defn get-block-referenced-blocks
 (defn get-block-referenced-blocks
-  ([block-uuid]
-   (get-block-referenced-blocks block-uuid {}))
-  ([block-uuid options]
+  ([block-id]
+   (get-block-referenced-blocks block-id {}))
+  ([block-id options]
    (when-let [repo (state/get-current-repo)]
    (when-let [repo (state/get-current-repo)]
      (when (conn/get-db repo)
      (when (conn/get-db repo)
-       (let [block (db-utils/entity [:block/uuid block-uuid])
+       (let [block (db-utils/entity block-id)
              query-result (->> (react/q repo [:frontend.worker.react/refs
              query-result (->> (react/q repo [:frontend.worker.react/refs
                                               (:db/id block)]
                                               (:db/id block)]
-                                 {}
-                                 '[:find [(pull ?ref-block ?block-attrs) ...]
-                                   :in $ ?block-uuid ?block-attrs
-                                   :where
-                                   [?block :block/uuid ?block-uuid]
-                                   [?ref-block :block/refs ?block]]
-                                 block-uuid
-                                 block-attrs)
+                                        {}
+                                        '[:find [(pull ?ref-block ?block-attrs) ...]
+                                          :in $ ?block-id ?block-attrs
+                                          :where
+                                          [?ref-block :block/refs ?block-id]]
+                                        block-id
+                                        block-attrs)
                                react
                                react
                                (sort-by-left-recursive))]
                                (sort-by-left-recursive))]
          (db-utils/group-by-page query-result))))))
          (db-utils/group-by-page query-result))))))
@@ -822,7 +749,7 @@ independent of format as format specific heading characters are stripped"
 (defn journal-page?
 (defn journal-page?
   "sanitized page-name only"
   "sanitized page-name only"
   [page-name]
   [page-name]
-  (:block/journal? (db-utils/entity [:block/name page-name])))
+  (:block/journal? (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page-name))))
 
 
 (defn get-block-property-values
 (defn get-block-property-values
   "Get blocks which have this property."
   "Get blocks which have this property."
@@ -856,6 +783,7 @@ independent of format as format specific heading characters are stripped"
   [files]
   [files]
   (mapv (fn [path] [:db.fn/retractEntity [:file/path path]]) files))
   (mapv (fn [path] [:db.fn/retractEntity [:file/path path]]) files))
 
 
+;; file-based only so it's safe to use :block/name lookup refs here
 (defn delete-pages-by-files
 (defn delete-pages-by-files
   [files]
   [files]
   (let [pages (->> (mapv get-file-page files)
   (let [pages (->> (mapv get-file-page files)
@@ -884,57 +812,10 @@ independent of format as format specific heading characters are stripped"
            page-id)
            page-id)
       ffirst))
       ffirst))
 
 
-(defn get-namespace-pages
-  "Accepts both sanitized and unsanitized namespaces"
-  [repo namespace]
-  (ldb/get-namespace-pages (conn/get-db repo) namespace {:db-graph? (config/db-based-graph? repo)}))
-
-(defn- tree [flat-col root]
-  (let [sort-fn #(sort-by :block/name %)
-        children (group-by :block/namespace flat-col)
-        namespace-children (fn namespace-children [parent-id]
-                             (map (fn [m]
-                                    (assoc m :namespace/children
-                                           (sort-fn (namespace-children {:db/id (:db/id m)}))))
-                                  (sort-fn (get children parent-id))))]
-    (namespace-children root)))
-
-(defn get-namespace-hierarchy
-  "Unsanitized namespaces"
-  [repo namespace]
-  (let [children (get-namespace-pages repo namespace)
-        namespace-id (:db/id (db-utils/entity [:block/name (util/page-name-sanity-lc namespace)]))
-        root {:db/id namespace-id}
-        col (conj children root)]
-    (tree col root)))
-
-(defn get-page-namespace
-  [repo page]
-  (:block/namespace (db-utils/entity repo [:block/name (util/page-name-sanity-lc page)])))
-
-(defn get-page-namespace-routes
-  [repo page]
-  (assert (string? page))
-  (when-let [db (conn/get-db repo)]
-    (when-not (string/blank? page)
-      (let [page (util/page-name-sanity-lc (string/trim page))
-            page-exist? (db-utils/entity repo [:block/name page])
-            ids (if page-exist?
-                  '()
-                  (->> (d/datoms db :aevt :block/name)
-                       (filter (fn [datom]
-                                 (string/ends-with? (:v datom) (str "/" page))))
-                       (map :e)))]
-        (when (seq ids)
-          (db-utils/pull-many repo
-                              '[:db/id :block/name :block/original-name
-                                {:block/file [:db/id :file/path]}]
-                              ids))))))
-
 (defn whiteboard-page?
 (defn whiteboard-page?
   "Given a page name or a page object, check if it is a whiteboard page"
   "Given a page name or a page object, check if it is a whiteboard page"
   [page]
   [page]
-  (ldb/whiteboard-page? (conn/get-db) page))
+  (ldb/whiteboard-page? page))
 
 
 (defn get-orphaned-pages
 (defn get-orphaned-pages
   [opts]
   [opts]
@@ -946,18 +827,10 @@ independent of format as format specific heading characters are stripped"
                                       sqlite-create-graph/built-in-pages-names
                                       sqlite-create-graph/built-in-pages-names
                                       gp-db/built-in-pages-names)}))))
                                       gp-db/built-in-pages-names)}))))
 
 
-(defn- block-or-page
-  [page-name-or-uuid]
-  (let [entity (get-page (str page-name-or-uuid))]
-    (if-not (some? (:block/name entity)) :block :page)))
-
-(defn page?
-  [page-name-or-uuid]
-  (= :page (block-or-page page-name-or-uuid)))
-
+;; FIXME: use `Untitled` instead of UUID for db based graphs
 (defn untitled-page?
 (defn untitled-page?
   [page-name]
   [page-name]
-  (when-let [entity (db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])]
+  (when (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page-name))
     (some? (parse-uuid page-name))))
     (some? (parse-uuid page-name))))
 
 
 (defn get-all-whiteboards
 (defn get-all-whiteboards
@@ -973,14 +846,17 @@ independent of format as format specific heading characters are stripped"
     (conn/get-db repo)))
     (conn/get-db repo)))
 
 
 (defn get-whiteboard-id-nonces
 (defn get-whiteboard-id-nonces
-  [repo page-name]
-  (let [key (if (config/db-based-graph? repo)
-              (:block/uuid (db-utils/entity :logseq.property.tldraw/shape))
+  [repo page-id]
+  (let [db-based? (config/db-based-graph? repo)
+        key (if db-based?
+              :logseq.property.tldraw/shape
               :logseq.tldraw.shape)
               :logseq.tldraw.shape)
-        page (db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])]
+        page (db-utils/entity page-id)]
     (->> (:block/_page page)
     (->> (:block/_page page)
-         (keep (fn [{:block/keys [uuid properties]}]
-                 (when-let [shape (get properties key)]
+         (keep (fn [{:block/keys [uuid] :as b}]
+                 (when-let [shape (if db-based?
+                                    (get b key)
+                                    (get (:block/properties b) key))]
                    {:id (str uuid)
                    {:id (str uuid)
                     :nonce (:nonce shape)}))))))
                     :nonce (:nonce shape)}))))))
 
 

+ 0 - 12
src/main/frontend/db/query_dsl.cljs

@@ -44,7 +44,6 @@
 ;; sample
 ;; sample
 ;; full-text-search ""
 ;; full-text-search ""
 
 
-;; namespace
 ;; page-property (page)
 ;; page-property (page)
 ;; page-tags (page)
 ;; page-tags (page)
 ;; all-page-tags
 ;; all-page-tags
@@ -373,14 +372,6 @@
     {:query (list 'page '?b page-name)
     {:query (list 'page '?b page-name)
      :rules [:page]}))
      :rules [:page]}))
 
 
-(defn- build-namespace
-  [e]
-  (let [page-name (page-ref/get-page-name! (str (first (rest e))))
-        page (util/page-name-sanity-lc page-name)]
-    (when-not (string/blank? page)
-      {:query (list 'namespace '?p page)
-       :rules [:namespace]})))
-
 (defn- build-page-ref
 (defn- build-page-ref
   [e]
   [e]
   (let [page-name (-> (page-ref/get-page-name! e)
   (let [page-name (-> (page-ref/get-page-name! e)
@@ -445,9 +436,6 @@ Some bindings in this fn:
        (= 'page fe)
        (= 'page fe)
        (build-page e)
        (build-page e)
 
 
-       (= 'namespace fe)
-       (build-namespace e)
-
        (= 'page-property fe)
        (= 'page-property fe)
        (build-page-property e env)
        (build-page-property e env)
 
 

+ 8 - 5
src/main/frontend/db/react.cljs

@@ -12,7 +12,9 @@
             [clojure.core.async :as async]
             [clojure.core.async :as async]
             [frontend.db.async.util :as db-async-util]
             [frontend.db.async.util :as db-async-util]
             [promesa.core :as p]
             [promesa.core :as p]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [logseq.common.util :as common-util]
+            [logseq.db :as ldb]))
 
 
 ;; Query atom of map of Key ([repo q inputs]) -> atom
 ;; Query atom of map of Key ([repo q inputs]) -> atom
 ;; TODO: replace with LRUCache, only keep the latest 20 or 50 items?
 ;; TODO: replace with LRUCache, only keep the latest 20 or 50 items?
@@ -157,13 +159,14 @@
                :page
                :page
                (get-in match [:path-params :name])
                (get-in match [:path-params :name])
 
 
-               :file
-               (get-in match [:path-params :path])
+               :whiteboard
+               (get-in match [:path-params :name])
 
 
                (date/journal-name))]
                (date/journal-name))]
     (when page
     (when page
-      (let [page-name (util/page-name-sanity-lc page)]
-        (db-utils/entity [:block/name page-name])))))
+      (if (common-util/uuid-string? page)
+        (db-utils/entity [:block/uuid (uuid page)])
+        (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page))))))
 
 
 (defn- execute-query!
 (defn- execute-query!
   [graph db k {:keys [query inputs transform-fn query-fn inputs-fn result]
   [graph db k {:keys [query inputs transform-fn query-fn inputs-fn result]

+ 1 - 1
src/main/frontend/db/rtc/debug_ui.cljs

@@ -88,7 +88,7 @@
             :auto-push-updates? (:auto-push-updates? state)
             :auto-push-updates? (:auto-push-updates? state)
             :current-page (state/get-current-page)
             :current-page (state/get-current-page)
             :blocks-count (when-let [page (state/get-current-page)]
             :blocks-count (when-let [page (state/get-current-page)]
-                            (count (:block/_page (db/entity [:block/name (util/page-name-sanity-lc page)]))))}
+                            (count (:block/_page (db/entity (ldb/get-first-page-by-name (db/get-db) page)))))}
            (fipp/pprint {:width 20})
            (fipp/pprint {:width 20})
            with-out-str)]]
            with-out-str)]]
 
 

+ 22 - 14
src/main/frontend/db_worker.cljs

@@ -30,7 +30,8 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.outliner.op :as outliner-op]
             [logseq.outliner.op :as outliner-op]
             [promesa.core :as p]
             [promesa.core :as p]
-            [shadow.cljs.modern :refer [defclass]]))
+            [shadow.cljs.modern :refer [defclass]]
+            [logseq.common.util :as common-util]))
 
 
 (defonce *sqlite worker-state/*sqlite)
 (defonce *sqlite worker-state/*sqlite)
 (defonce *sqlite-conns worker-state/*sqlite-conns)
 (defonce *sqlite-conns worker-state/*sqlite-conns)
@@ -304,7 +305,9 @@
    (when-let [conn (worker-state/get-datascript-conn repo)]
    (when-let [conn (worker-state/get-datascript-conn repo)]
      (let [selector (ldb/read-transit-str selector-str)
      (let [selector (ldb/read-transit-str selector-str)
            id (ldb/read-transit-str id-str)
            id (ldb/read-transit-str id-str)
-           result (->> (d/pull @conn selector id)
+           eid (when (and (vector? id) (= :block/name (first id)))
+                 (ldb/get-first-page-by-name @conn (second id)))
+           result (->> (d/pull @conn selector (or eid id))
                        (sqlite-common-db/with-parent-and-left @conn))]
                        (sqlite-common-db/with-parent-and-left @conn))]
        (ldb/write-transit-str result))))
        (ldb/write-transit-str result))))
 
 
@@ -323,10 +326,11 @@
        (ldb/write-transit-str result))))
        (ldb/write-transit-str result))))
 
 
   (get-block-and-children
   (get-block-and-children
-   [_this repo name children?]
-   (assert (string? name))
+   [_this repo id-str children?]
+   (assert (common-util/uuid-string? id-str))
    (when-let [conn (worker-state/get-datascript-conn repo)]
    (when-let [conn (worker-state/get-datascript-conn repo)]
-     (ldb/write-transit-str (sqlite-common-db/get-block-and-children @conn name children?))))
+     (let [id (uuid id-str)]
+       (ldb/write-transit-str (sqlite-common-db/get-block-and-children @conn id children?)))))
 
 
   (get-block-refs
   (get-block-refs
    [_this repo id]
    [_this repo id]
@@ -484,19 +488,21 @@
      (search/page-search repo @conn q limit)))
      (search/page-search repo @conn q limit)))
 
 
   (page-rename
   (page-rename
-   [this repo old-name new-name]
+   [this repo page-uuid-str new-name]
+   (assert (common-util/uuid-string? page-uuid-str))
    (when-let [conn (worker-state/get-datascript-conn repo)]
    (when-let [conn (worker-state/get-datascript-conn repo)]
      (let [config (worker-state/get-config repo)
      (let [config (worker-state/get-config repo)
-           result (worker-page-rename/rename! repo conn config old-name new-name)]
+           result (worker-page-rename/rename! repo conn config (uuid page-uuid-str) new-name)]
        (bean/->js {:result result}))))
        (bean/->js {:result result}))))
 
 
   (page-delete
   (page-delete
-   [this repo page-name]
+   [this repo page-uuid-str]
+   (assert (common-util/uuid-string? page-uuid-str))
    (when-let [conn (worker-state/get-datascript-conn repo)]
    (when-let [conn (worker-state/get-datascript-conn repo)]
      (let [error-handler (fn [{:keys [msg]}]
      (let [error-handler (fn [{:keys [msg]}]
                            (worker-util/post-message :notification
                            (worker-util/post-message :notification
                                                      [[:div [:p msg]] :error]))
                                                      [[:div [:p msg]] :error]))
-           result (worker-page/delete! repo conn page-name {:error-handler error-handler})]
+           result (worker-page/delete! repo conn (uuid page-uuid-str) {:error-handler error-handler})]
        (bean/->js {:result result}))))
        (bean/->js {:result result}))))
 
 
   (apply-outliner-ops
   (apply-outliner-ops
@@ -537,11 +543,13 @@
 
 
   ;; Export
   ;; Export
   (block->content
   (block->content
-   [this repo block-uuid-or-page-name tree->file-opts context]
-   (when-let [conn (worker-state/get-datascript-conn repo)]
-     (worker-export/block->content repo @conn block-uuid-or-page-name
-                                   (ldb/read-transit-str tree->file-opts)
-                                   (ldb/read-transit-str context))))
+   [this repo block-uuid-str tree->file-opts context]
+   (assert (common-util/uuid-string? block-uuid-str))
+   (let [block-uuid (uuid block-uuid-str)]
+     (when-let [conn (worker-state/get-datascript-conn repo)]
+       (worker-export/block->content repo @conn block-uuid
+                                     (ldb/read-transit-str tree->file-opts)
+                                     (ldb/read-transit-str context)))))
 
 
   (get-all-pages
   (get-all-pages
    [this repo]
    [this repo]

+ 0 - 1
src/main/frontend/extensions/pdf/assets.cljs

@@ -163,7 +163,6 @@
         (let [label (:filename pdf-current)]
         (let [label (:filename pdf-current)]
           (p/do!
           (p/do!
            (page-handler/<create! page-name {:redirect?        false :create-first-block? false
            (page-handler/<create! page-name {:redirect?        false :create-first-block? false
-                                             :split-namespace? false
                                              :format           format
                                              :format           format
                                              ;; FIXME: file and file-path properties for db version
                                              ;; FIXME: file and file-path properties for db version
                                              :properties       {:file      (case format
                                              :properties       {:file      (case format

+ 2 - 2
src/main/frontend/extensions/slide.cljs

@@ -93,8 +93,8 @@
         page (db/entity [:block/name page-name])
         page (db/entity [:block/name page-name])
         journal? (:journal? page)
         journal? (:journal? page)
         repo (state/get-current-repo)
         repo (state/get-current-repo)
-        blocks (-> (db/get-page-blocks-no-cache repo page-name)
-                   (outliner-tree/blocks->vec-tree page-name))
+        blocks (-> (db/get-page-blocks-no-cache repo (:db/id page))
+                   (outliner-tree/blocks->vec-tree (:db/id page)))
         blocks (if journal?
         blocks (if journal?
                  (rest blocks)
                  (rest blocks)
                  blocks)
                  blocks)

+ 16 - 13
src/main/frontend/extensions/tldraw.cljs

@@ -25,7 +25,8 @@
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.components.whiteboard :as whiteboard]
             [frontend.components.whiteboard :as whiteboard]
             [cljs-bean.core :as bean]
             [cljs-bean.core :as bean]
-            [frontend.db.async :as db-async]))
+            [frontend.db.async :as db-async]
+            [logseq.common.util :as common-util]))
 
 
 (def tldraw (r/adapt-class (gobj/get TldrawLogseq "App")))
 (def tldraw (r/adapt-class (gobj/get TldrawLogseq "App")))
 
 
@@ -114,7 +115,9 @@
                         (if (util/uuid-string? block-id-str)
                         (if (util/uuid-string? block-id-str)
                           (:block/name (model/get-block-page (state/get-current-repo) (parse-uuid block-id-str)))
                           (:block/name (model/get-block-page (state/get-current-repo) (parse-uuid block-id-str)))
                           (:block/name (db/entity [:block/name (util/page-name-sanity-lc block-id-str)]))))
                           (:block/name (db/entity [:block/name (util/page-name-sanity-lc block-id-str)]))))
-   :exportToImage (fn [page-name options] (state/set-modal! #(export/export-blocks page-name (merge (js->clj options :keywordize-keys true) {:whiteboard? true}))))
+   :exportToImage (fn [page-uuid-str options]
+                    (assert (common-util/uuid-string? page-uuid-str))
+                    (state/set-modal! #(export/export-blocks (uuid page-uuid-str) (merge (js->clj options :keywordize-keys true) {:whiteboard? true}))))
    :isWhiteboardPage model/whiteboard-page?
    :isWhiteboardPage model/whiteboard-page?
    :isMobile util/mobile?
    :isMobile util/mobile?
    :saveAsset save-asset-handler
    :saveAsset save-asset-handler
@@ -133,17 +136,17 @@
                       (state/sidebar-add-block! (state/get-current-repo)
                       (state/sidebar-add-block! (state/get-current-repo)
                                                 (:db/id (model/get-page uuid))
                                                 (:db/id (model/get-page uuid))
                                                 (keyword type)))
                                                 (keyword type)))
-   :redirectToPage (fn [page-name-or-uuid]
-                     (let [page-name (or (when (util/uuid-string? page-name-or-uuid)
-                                           (:block/name (model/get-block-page (state/get-current-repo)
-                                                                              (parse-uuid page-name-or-uuid))))
-                                         page-name-or-uuid)
-                           page-exists? (model/page-exists? page-name)
-                           whiteboard? (model/whiteboard-page? page-name)]
-                       (when page-exists?
-                         (if whiteboard?
-                           (route-handler/redirect-to-whiteboard! page-name {:block-id page-name-or-uuid})
-                           (route-handler/redirect-to-page! (model/get-redirect-page-name page-name-or-uuid))))))})
+   :redirectToPage (fn [block-uuid-str]
+                     (when (and block-uuid-str (common-util/uuid-string? block-uuid-str))
+                       (let [block-id (parse-uuid block-uuid-str)
+                             page (model/get-block-page (state/get-current-repo) block-id)
+                             whiteboard? (model/whiteboard-page? page)]
+                         (when page
+                           (if whiteboard?
+                             (route-handler/redirect-to-page! (:block/uuid page)
+                                                              (when (not= block-id (:block/uuid page))
+                                                                {:block-id block-id}))
+                             (route-handler/redirect-to-page! (model/get-redirect-page-name (:block/name page))))))))})
 
 
 (defonce *transact-result (atom nil))
 (defonce *transact-result (atom nil))
 
 

+ 1 - 0
src/main/frontend/extensions/zotero/handler.cljs

@@ -78,6 +78,7 @@
         (p/do!
         (p/do!
          (when-not (str/blank? page-name)
          (when-not (str/blank? page-name)
            (if (db/page-exists? (str/lower-case page-name))
            (if (db/page-exists? (str/lower-case page-name))
+             ;; FIXME: Overwrite if it has a zotero tag (which means created by Zotero)
              (if (setting/setting :overwrite-mode?)
              (if (setting/setting :overwrite-mode?)
                (page-handler/<delete!
                (page-handler/<delete!
                 page-name
                 page-name

+ 23 - 20
src/main/frontend/handler/common/page.cljs

@@ -102,13 +102,14 @@
 
 
 (defn- find-block-in-favorites-page
 (defn- find-block-in-favorites-page
   [page-block-uuid]
   [page-block-uuid]
-  (let [db (conn/get-db)
-        blocks (ldb/get-page-blocks db common-config/favorites-page-name {})]
-    (when-let [page-block-entity (d/entity db [:block/uuid page-block-uuid])]
-      (some (fn [block]
-              (when (= (:db/id (:block/link block)) (:db/id page-block-entity))
-                block))
-            blocks))))
+  (let [db (conn/get-db)]
+    (when-let [page-id (ldb/get-first-page-by-name db common-config/favorites-page-name)]
+      (let [blocks (ldb/get-page-blocks db page-id {})]
+        (when-let [page-block-entity (d/entity db [:block/uuid page-block-uuid])]
+          (some (fn [block]
+                  (when (= (:db/id (:block/link block)) (:db/id page-block-entity))
+                    block))
+                blocks))))))
 
 
 (defn favorited?-v2
 (defn favorited?-v2
   [page-block-uuid]
   [page-block-uuid]
@@ -144,17 +145,20 @@
   "Deletes a page. If delete is successful calls ok-handler. Otherwise calls error-handler
   "Deletes a page. If delete is successful calls ok-handler. Otherwise calls error-handler
    if given. Note that error-handler is being called in addition to error messages that worker
    if given. Note that error-handler is being called in addition to error messages that worker
    already provides"
    already provides"
-  [page-name ok-handler & {:keys [error-handler]}]
-  (when page-name
-    (when-let [^Object worker @state/*db-worker]
-      (-> (p/let [repo (state/get-current-repo)
-                  res (.page-delete worker repo page-name)
-                  res' (gobj/get res "result")]
-            (if res'
-              (when ok-handler (ok-handler))
-              (when error-handler (error-handler))))
-          (p/catch (fn [error]
-                     (js/console.error error)))))))
+  [page-uuid-or-name ok-handler & {:keys [error-handler]}]
+  (when page-uuid-or-name
+    (assert (or (uuid? page-uuid-or-name) (string? page-uuid-or-name)))
+    (when-let [page-uuid (or (and (uuid? page-uuid-or-name) page-uuid-or-name)
+                             (:block/uuid (db/entity (ldb/get-first-page-by-name (db/get-db) page-uuid-or-name))))]
+      (when-let [^Object worker @state/*db-worker]
+        (-> (p/let [repo (state/get-current-repo)
+                    res (.page-delete worker repo (str page-uuid))
+                    res' (gobj/get res "result")]
+              (if res'
+                (when ok-handler (ok-handler))
+                (when error-handler (error-handler))))
+            (p/catch (fn [error]
+                       (js/console.error error))))))))
 
 
 ;; other fns
 ;; other fns
 ;; =========
 ;; =========
@@ -202,13 +206,12 @@
   (let [db-based?           (config/db-based-graph? repo)
   (let [db-based?           (config/db-based-graph? repo)
         old-page-name       (common-util/page-name-sanity-lc old-name)
         old-page-name       (common-util/page-name-sanity-lc old-name)
         new-page-name       (common-util/page-name-sanity-lc new-name)
         new-page-name       (common-util/page-name-sanity-lc new-name)
-        page (db/entity [:block/name new-page-name])
         redirect? (= (some-> (state/get-current-page) common-util/page-name-sanity-lc)
         redirect? (= (some-> (state/get-current-page) common-util/page-name-sanity-lc)
                      (common-util/page-name-sanity-lc old-page-name))]
                      (common-util/page-name-sanity-lc old-page-name))]
 
 
     ;; Redirect to the newly renamed page
     ;; Redirect to the newly renamed page
     (when redirect?
     (when redirect?
-      (route-handler/redirect! {:to          (if (model/whiteboard-page? page) :whiteboard :page)
+      (route-handler/redirect! {:to          :page
                                 :push        false
                                 :push        false
                                 :path-params {:name new-page-name}}))
                                 :path-params {:name new-page-name}}))
 
 

+ 1 - 1
src/main/frontend/handler/db_based/property.cljs

@@ -531,7 +531,7 @@
 
 
 (defn- get-property-hidden-page
 (defn- get-property-hidden-page
   [property]
   [property]
-  (let [page-name (str db-property-util/hidden-page-name-prefix (:db/ident property))]
+  (let [page-name (str db-property-util/hidden-page-name-prefix (:block/uuid property))]
     (or (db/entity [:block/name page-name])
     (or (db/entity [:block/name page-name])
         (db-property-util/build-property-hidden-page property))))
         (db-property-util/build-property-hidden-page property))))
 
 

+ 6 - 4
src/main/frontend/handler/editor.cljs

@@ -3473,12 +3473,14 @@
                       (state/get-current-page)
                       (state/get-current-page)
                       (date/today))]
                       (date/today))]
     (let [block-id (or root-block (parse-uuid page))
     (let [block-id (or root-block (parse-uuid page))
+          page-id (when-not block-id
+                    (ldb/get-first-page-by-name (db/get-db) page))
           blocks (if block-id
           blocks (if block-id
                    (db/get-block-and-children (state/get-current-repo) block-id)
                    (db/get-block-and-children (state/get-current-repo) block-id)
-                   (db/get-page-blocks-no-cache page))
+                   (db/get-page-blocks-no-cache page-id))
           root-block (or block-id root-block)]
           root-block (or block-id root-block)]
       (if incremental?
       (if incremental?
-        (let [blocks (tree/blocks->vec-tree blocks (or block-id page))]
+        (let [blocks (tree/blocks->vec-tree blocks (or block-id page-id))]
           (->>
           (->>
            (cond->> blocks
            (cond->> blocks
              root-block
              root-block
@@ -3882,7 +3884,7 @@
 
 
 (defn block->data-transfer!
 (defn block->data-transfer!
   "Set block or page name to the given event's dataTransfer. Used in dnd."
   "Set block or page name to the given event's dataTransfer. Used in dnd."
-  [block-or-page-name event]
+  [block-or-page-name event page?]
   (.setData (gobj/get event "dataTransfer")
   (.setData (gobj/get event "dataTransfer")
-            (if (db-model/page? block-or-page-name) "page-name" "block-uuid")
+            (if page? "page-name" "block-uuid")
             (str block-or-page-name)))
             (str block-or-page-name)))

+ 1 - 1
src/main/frontend/handler/events.cljs

@@ -759,7 +759,7 @@
   (state/set-state! :whiteboard/linked-shapes shapes))
   (state/set-state! :whiteboard/linked-shapes shapes))
 
 
 (defmethod handle :whiteboard-go-to-link [[_ link]]
 (defmethod handle :whiteboard-go-to-link [[_ link]]
-  (route-handler/redirect! {:to :whiteboard
+  (route-handler/redirect! {:to :page
                             :path-params {:name link}}))
                             :path-params {:name link}}))
 
 
 (defmethod handle :graph/dir-gone [[_ dir]]
 (defmethod handle :graph/dir-gone [[_ dir]]

+ 11 - 18
src/main/frontend/handler/export/common.cljs

@@ -16,7 +16,8 @@
             [promesa.core :as p]
             [promesa.core :as p]
             [frontend.persist-db.browser :as db-browser]
             [frontend.persist-db.browser :as db-browser]
             [frontend.worker.export :as worker-export]
             [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
 ;;; TODO: split frontend.handler.export.text related states
 (def ^:dynamic *state*
 (def ^:dynamic *state*
@@ -90,31 +91,23 @@
                (mapv remove-block-ast-pos
                (mapv remove-block-ast-pos
                      (mldoc/->edn content format))))))
                      (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
 (defn get-page-content
-  [page-name]
+  [page-uuid]
   (let [repo (state/get-current-repo)
   (let [repo (state/get-current-repo)
         db (db/get-db repo)]
         db (db/get-db repo)]
-    (worker-export/block->content repo db page-name
+    (worker-export/block->content repo db page-uuid
                                   nil
                                   nil
                                   {:export-bullet-indentation (state/get-export-bullet-indentation)})))
                                   {:export-bullet-indentation (state/get-export-bullet-indentation)})))
 
 
 (defn- page-name->ast
 (defn- page-name->ast
   [page-name]
   [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
 (defn- update-level-in-block-ast-coll
   [block-ast-coll origin-level]
   [block-ast-coll origin-level]

+ 7 - 7
src/main/frontend/handler/export/html.cljs

@@ -416,15 +416,15 @@
 
 
 (defn export-blocks-as-html
 (defn export-blocks-as-html
   "options: see also `export-blocks-as-markdown`"
   "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
   (let [content
-        (if (string? root-block-uuids-or-page-name)
+        (if (uuid? root-block-uuids-or-page-uuid)
           ;; page
           ;; 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))]
         format (or (:block/format first-block) (state/get-preferred-format))]
     (export-helper content format options)))
     (export-helper content format options)))
 
 

+ 9 - 9
src/main/frontend/handler/export/opml.cljs

@@ -433,20 +433,20 @@
 
 
 (defn export-blocks-as-opml
 (defn export-blocks-as-opml
   "options: see also `export-blocks-as-markdown`"
   "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
   (util/profile
    :export-blocks-as-opml
    :export-blocks-as-opml
    (let [content
    (let [content
-         (if (string? root-block-uuids-or-page-name)
+         (if (uuid? root-block-uuids-or-page-uuid)
            ;; page
            ;; 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")
                  "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))]
          format (or (:block/format first-block) (state/get-preferred-format))]
      (export-helper content format options :title title))))
      (export-helper content format options :title title))))
 
 

+ 10 - 10
src/main/frontend/handler/export/text.cljs

@@ -509,20 +509,20 @@
   :indent-style \"dashes\" | \"spaces\" | \"no-indent\"
   :indent-style \"dashes\" | \"spaces\" | \"no-indent\"
   :remove-options [:emphasis :page-ref :tag :property]
   :remove-options [:emphasis :page-ref :tag :property]
   :other-options {:keep-only-level<=N int :newline-after-block bool}"
   :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
   (util/profile
    :export-blocks-as-markdown
    :export-blocks-as-markdown
    (try
    (try
      (let [content
      (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
      (catch :default e
        (js/console.error e)))))
        (js/console.error e)))))
 
 

+ 45 - 57
src/main/frontend/handler/graph.cljs

@@ -9,7 +9,8 @@
             [frontend.config :as config]
             [frontend.config :as config]
             [logseq.graph-parser.db :as gp-db]
             [logseq.graph-parser.db :as gp-db]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [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
 (defn- build-links
   [links]
   [links]
@@ -19,9 +20,8 @@
        links))
        links))
 
 
 (defn- build-nodes
 (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 (set (flatten nodes))]
     (->>
     (->>
      pages
      pages
@@ -39,13 +39,10 @@
                            color)
                            color)
                    n (get page-links p 1)
                    n (get page-links p 1)
                    size (int (* 8 (max 1.0 (js/Math.cbrt n))))]
                    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
                   ;; slow
 (defn- uuid-or-asset?
 (defn- uuid-or-asset?
@@ -92,7 +89,6 @@
     (when-let [repo (state/get-current-repo)]
     (when-let [repo (state/get-current-repo)]
       (let [relation (db/get-pages-relation repo journal?)
       (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))
             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))
             tags (set (map second tagged-pages))
             full-pages (db/get-all-pages repo)
             full-pages (db/get-all-pages repo)
             full-pages-map (into {} (map (juxt :block/name identity) full-pages))
             full-pages-map (into {} (map (juxt :block/name identity) full-pages))
@@ -110,8 +106,7 @@
               (not excluded-pages?)
               (not excluded-pages?)
               (remove (fn [p] (true? (pu/get-block-property-value p :logseq.property/exclude-from-graph-view)))))
               (remove (fn [p] (true? (pu/get-block-property-value p :logseq.property/exclude-from-graph-view)))))
             links (concat (seq relation)
             links (concat (seq relation)
-                          (seq tagged-pages)
-                          (seq namespaces))
+                          (seq tagged-pages))
             linked (set (flatten links))
             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)
             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)
                                 (map string/lower-case)
@@ -125,7 +120,7 @@
             page-links (reduce (fn [m [k v]] (-> (update m k inc)
             page-links (reduce (fn [m [k v]] (-> (update m k inc)
                                                  (update v inc))) {} links)
                                                  (update v inc))) {} links)
             links (build-links (remove (fn [[_ to]] (nil? to)) 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)
         (-> {:nodes (map #(assoc % :block/created-at (get-in full-pages-map [(:id %) :block/created-at])) nodes)
              :links links
              :links links
              :page-name->original-name page-name->original-name}
              :page-name->original-name page-name->original-name}
@@ -138,18 +133,16 @@
   [page theme show-journal]
   [page theme show-journal]
   (let [dark? (= "dark" theme)]
   (let [dark? (= "dark" theme)]
     (when-let [repo (state/get-current-repo)]
     (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)
             tags (if (config/db-based-graph? repo)
                    (set (map #(:block/name (db/entity repo (:db/id %)))
                    (set (map #(:block/name (db/entity repo (:db/id %)))
                              (:block/tags page-entity)))
                              (:block/tags page-entity)))
                    (:tags (:block/properties page-entity)))
                    (:tags (:block/properties page-entity)))
             tags (remove #(= page %) tags)
             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
             links (concat
-                   namespaces
                    (map (fn [[p _aliases]]
                    (map (fn [[p _aliases]]
                           [page p]) ref-pages)
                           [page p]) ref-pages)
                    (map (fn [[p _aliases]]
                    (map (fn [[p _aliases]]
@@ -163,10 +156,11 @@
                              (set))
                              (set))
             other-pages-links (mapcat
             other-pages-links (mapcat
                                (fn [page]
                                (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)
                                                      (set/intersection other-pages))
                                                      (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)
                                                            (set/intersection other-pages))]
                                                            (set/intersection other-pages))]
                                    (concat
                                    (concat
@@ -184,7 +178,7 @@
                         tags)
                         tags)
                        (remove nil?)
                        (remove nil?)
                        (distinct))
                        (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)
             full-pages (db/get-all-pages repo)
             all-pages (map common-util/get-page-original-name full-pages)
             all-pages (map common-util/get-page-original-name full-pages)
             page-name->original-name (zipmap (map :block/name full-pages) all-pages)]
             page-name->original-name (zipmap (map :block/name full-pages) all-pages)]
@@ -196,40 +190,34 @@
 (defn build-block-graph
 (defn build-block-graph
   "Builds a citation/reference graph for a given block uuid."
   "Builds a citation/reference graph for a given block uuid."
   [block theme]
   [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
                        ;; 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
 (defn n-hops
   "Get all nodes that are n hops from nodes (a collection of node ids)"
   "Get all nodes that are n hops from nodes (a collection of node ids)"

+ 41 - 32
src/main/frontend/handler/page.cljs

@@ -31,7 +31,6 @@
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.page-ref :as page-ref]
             [promesa.core :as p]
             [promesa.core :as p]
             [logseq.common.path :as path]
             [logseq.common.path :as path]
-            [frontend.handler.property.util :as pu]
             [electron.ipc :as ipc]
             [electron.ipc :as ipc]
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
             [frontend.persist-db.browser :as db-browser]
             [frontend.persist-db.browser :as db-browser]
@@ -86,12 +85,14 @@
   (when-let [db (conn/get-db)]
   (when-let [db (conn/get-db)]
     (let [repo (state/get-current-repo)]
     (let [repo (state/get-current-repo)]
       (if (config/db-based-graph? repo)
       (if (config/db-based-graph? repo)
-        (let [blocks (ldb/sort-by-left
-                      (ldb/get-page-blocks db common-config/favorites-page-name {})
-                      (d/entity db [:block/name common-config/favorites-page-name]))]
-          (keep (fn [block]
-                  (when-let [block-db-id (:db/id (:block/link block))]
-                    (d/entity db block-db-id))) blocks))
+        (when-let [page-id (ldb/get-first-page-by-name db common-config/favorites-page-name)]
+          (let [page (d/entity db page-id)
+                blocks (ldb/sort-by-left
+                        (ldb/get-page-blocks db page-id {})
+                        page)]
+            (keep (fn [block]
+                    (when-let [block-db-id (:db/id (:block/link block))]
+                      (d/entity db block-db-id))) blocks)))
         (let [page-names (->> (:favorites (state/sub-config))
         (let [page-names (->> (:favorites (state/sub-config))
                               (remove string/blank?)
                               (remove string/blank?)
                               (filter string?)
                               (filter string?)
@@ -125,25 +126,34 @@
         (<favorite-page! page-name)))))
         (<favorite-page! page-name)))))
 
 
 (defn rename!
 (defn rename!
-  [old-name new-name & {:as _opts}]
+  [page-uuid-or-old-name new-name & {:as _opts}]
   (when-let [^js worker @db-browser/*worker]
   (when-let [^js worker @db-browser/*worker]
     (p/let [repo (state/get-current-repo)
     (p/let [repo (state/get-current-repo)
-            result (.page-rename worker repo old-name new-name)
+            page-uuid (cond
+                        (uuid? page-uuid-or-old-name)
+                        page-uuid-or-old-name
+                        (common-util/uuid-string? page-uuid-or-old-name)
+                        page-uuid-or-old-name
+                        :else
+                        (:block/uuid (db/entity (ldb/get-first-page-by-name (db/get-db) page-uuid-or-old-name))))
+            result (.page-rename worker repo (str page-uuid) new-name)
             result' (:result (bean/->clj result))]
             result' (:result (bean/->clj result))]
       (case (if (string? result') (keyword result') result')
       (case (if (string? result') (keyword result') result')
         :built-in-page
         :built-in-page
-        (notification/show! "Built-in page's name cannot be modified" :error)
+        (notification/show! "Built-in page's name cannot be modified" :warning)
         :invalid-empty-name
         :invalid-empty-name
-        (notification/show! "Please use a valid name, empty name is not allowed!" :error)
-        :merge-whiteboard-pages
-        (notification/show! "Can't merge whiteboard pages" :error)
+        (notification/show! "Please use a valid name, empty name is not allowed!" :warning)
+        :rename-page-exists
+        (notification/show! "Another page with the new name exists already" :warning)
         nil))))
         nil))))
 
 
 (defn <reorder-favorites!
 (defn <reorder-favorites!
   [favorites]
   [favorites]
-  (let [conn (conn/get-db false)]
-    (when-let [favorites-page-entity (d/entity @conn [:block/name common-config/favorites-page-name])]
-      (let [favorite-page-block-db-id-coll
+  (let [conn (conn/get-db false)
+        db @conn]
+    (when-let [page-id (ldb/get-first-page-by-name db common-config/favorites-page-name)]
+      (let [favorites-page-entity (d/entity db page-id)
+            favorite-page-block-db-id-coll
             (keep (fn [page-name]
             (keep (fn [page-name]
                     (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
                     (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
                             :db/id))
                             :db/id))
@@ -242,14 +252,14 @@
         (common-handler/fix-pages-timestamps))))
         (common-handler/fix-pages-timestamps))))
 
 
 (defn get-filters
 (defn get-filters
-  [page-name]
-  (let [properties (db/get-page-properties page-name)]
-    (if (config/db-based-graph? (state/get-current-repo))
-      (pu/lookup properties :logseq.property/filters)
-      (let [properties-str (or (:filters properties) "{}")]
-        (try (reader/read-string properties-str)
-             (catch :default e
-               (log/error :syntax/filters e)))))))
+  [page]
+  (if (config/db-based-graph? (state/get-current-repo))
+    (:logseq.property/filters page)
+    (let [properties (:block/properties page)
+          properties-str (or (:filters properties) "{}")]
+      (try (reader/read-string properties-str)
+           (catch :default e
+             (log/error :syntax/filters e))))))
 
 
 (defn save-filter!
 (defn save-filter!
   [page-name filter-state]
   [page-name filter-state]
@@ -369,14 +379,13 @@
               template (state/get-default-journal-template)
               template (state/get-default-journal-template)
               create-f (fn []
               create-f (fn []
                          (p/do!
                          (p/do!
-                           (<create! title {:redirect? false
-                                          :split-namespace? false
-                                          :create-first-block? (not template)
-                                          :journal? true
-                                          :today-journal? true})
-                           (state/pub-event! [:journal/insert-template today-page])
-                           (ui-handler/re-render-root!)
-                           (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
+                          (<create! title {:redirect? false
+                                           :create-first-block? (not template)
+                                           :journal? true
+                                           :today-journal? true})
+                          (state/pub-event! [:journal/insert-template today-page])
+                          (ui-handler/re-render-root!)
+                          (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
           (when (db/page-empty? repo today-page)
           (when (db/page-empty? repo today-page)
             (if (config/db-based-graph? repo)
             (if (config/db-based-graph? repo)
               (let [page-exists (db/get-page today-page)]
               (let [page-exists (db/get-page today-page)]

+ 1 - 2
src/main/frontend/handler/query/builder.cljs

@@ -10,7 +10,6 @@
 (def operators [:and :or :not])
 (def operators [:and :or :not])
 (def operators-set (set operators))
 (def operators-set (set operators))
 (def page-filters ["all page tags"
 (def page-filters ["all page tags"
-                   "namespace"
                    "tags"
                    "tags"
                    "property"
                    "property"
                    "sample"])
                    "sample"])
@@ -155,7 +154,7 @@
               (last f))]
               (last f))]
       (into [(symbol (first f))] [(second f) l]))
       (into [(symbol (first f))] [(second f) l]))
 
 
-    (and (vector? f) (contains? #{:page :namespace :tags} (keyword (first f))))
+    (and (vector? f) (contains? #{:page :tags} (keyword (first f))))
     (into [(symbol (first f))] (map ->page-ref (rest f)))
     (into [(symbol (first f))] (map ->page-ref (rest f)))
 
 
     :else f))
     :else f))

+ 18 - 24
src/main/frontend/handler/route.cljs

@@ -72,33 +72,27 @@
   wrong new page with that name (#3511). page-name can be a block name or uuid"
   wrong new page with that name (#3511). page-name can be a block name or uuid"
   ([page-name]
   ([page-name]
    (redirect-to-page! page-name {}))
    (redirect-to-page! page-name {}))
-  ([page-name {:keys [anchor push click-from-recent?]
+  ([page-name {:keys [anchor push click-from-recent? block-id new-whiteboard?]
                :or {click-from-recent? false}}]
                :or {click-from-recent? false}}]
    (when (or (uuid? page-name) (seq page-name))
    (when (or (uuid? page-name) (seq page-name))
+     ;; Always skip onboarding when loading an existing whiteboard
+     (when-not new-whiteboard? (state/set-onboarding-whiteboard! true))
      (recent-handler/add-page-to-recent! (state/get-current-repo) page-name
      (recent-handler/add-page-to-recent! (state/get-current-repo) page-name
                                          click-from-recent?)
                                          click-from-recent?)
-     (let [m (cond->
-               (default-page-route page-name)
-
-               anchor
-               (assoc :query-params {:anchor anchor})
-
-              (boolean? push)
-              (assoc :push push))]
-       (redirect! m)))))
-
-(defn redirect-to-whiteboard!
-  ([name]
-   (redirect-to-whiteboard! name nil))
-  ([name {:keys [block-id new-whiteboard? click-from-recent?]}]
-   ;; Always skip onboarding when loading an existing whiteboard
-   (when-not new-whiteboard? (state/set-onboarding-whiteboard! true))
-   (recent-handler/add-page-to-recent! (state/get-current-repo) name click-from-recent?)
-   (if (= name (state/get-current-whiteboard))
-     (state/focus-whiteboard-shape block-id)
-     (redirect! {:to :whiteboard
-                 :path-params {:name (str name)}
-                 :query-params (merge {:block-id block-id})}))))
+     (if (and (= name (state/get-current-whiteboard)) block-id)
+       (state/focus-whiteboard-shape block-id)
+       (let [m (cond->
+                (default-page-route (str page-name))
+
+                 block-id
+                 (assoc :query-params {:block-id anchor})
+
+                 anchor
+                 (assoc :query-params {:anchor anchor})
+
+                 (boolean? push)
+                 (assoc :push push))]
+         (redirect! m))))))
 
 
 (defn get-title
 (defn get-title
   [name path-params]
   [name path-params]
@@ -210,4 +204,4 @@
                 :all-journals
                 :all-journals
                 :home)]
                 :home)]
     (redirect! {:to route}))
     (redirect! {:to route}))
-  (util/scroll-to-top))
+  (util/scroll-to-top))

+ 4 - 5
src/main/frontend/handler/whiteboard.cljs

@@ -144,7 +144,7 @@
         repo (state/get-current-repo)
         repo (state/get-current-repo)
         db-id-nonces (or
         db-id-nonces (or
                       (get-in @*last-shapes-nonce [repo page-name])
                       (get-in @*last-shapes-nonce [repo page-name])
-                      (set (->> (model/get-whiteboard-id-nonces repo page-name)
+                      (set (->> (model/get-whiteboard-id-nonces repo (:db/id page-block))
                                 (map #(update % :id str)))))
                                 (map #(update % :id str)))))
         {:keys [page-block new-shapes deleted-shapes upserted-blocks delete-blocks metadata] :as result}
         {:keys [page-block new-shapes deleted-shapes upserted-blocks delete-blocks metadata] :as result}
         (compute-tx app tl-page new-id-nonces db-id-nonces page-name replace?)]
         (compute-tx app tl-page new-id-nonces db-id-nonces page-name replace?)]
@@ -204,16 +204,15 @@
    (p/let [uuid (or (and name (parse-uuid name)) (d/squuid))
    (p/let [uuid (or (and name (parse-uuid name)) (d/squuid))
            name (or name (str uuid))
            name (or name (str uuid))
            _ (db/transact! (get-default-new-whiteboard-tx name uuid))]
            _ (db/transact! (get-default-new-whiteboard-tx name uuid))]
-     name)))
+     uuid)))
 
 
 (defn <create-new-whiteboard-and-redirect!
 (defn <create-new-whiteboard-and-redirect!
   ([]
   ([]
    (<create-new-whiteboard-and-redirect! (str (d/squuid))))
    (<create-new-whiteboard-and-redirect! (str (d/squuid))))
   ([name]
   ([name]
    (when-not config/publishing?
    (when-not config/publishing?
-     (p/do!
-       (<create-new-whiteboard-page! name)
-       (route-handler/redirect-to-whiteboard! name {:new-whiteboard? true})))))
+     (p/let [id (<create-new-whiteboard-page! name)]
+       (route-handler/redirect-to-page! id {:new-whiteboard? true})))))
 
 
 (defn ->logseq-portal-shape
 (defn ->logseq-portal-shape
   [block-id point]
   [block-id point]

+ 24 - 18
src/main/frontend/routes.cljs

@@ -13,7 +13,10 @@
             [frontend.components.bug-report :as bug-report]
             [frontend.components.bug-report :as bug-report]
             [frontend.components.user.login :as login]
             [frontend.components.user.login :as login]
             [logseq.shui.demo2 :as shui]
             [logseq.shui.demo2 :as shui]
-            [frontend.components.imports :as imports]))
+            [frontend.components.imports :as imports]
+            [frontend.config :as config]
+            [logseq.db :as ldb]
+            [frontend.db :as db]))
 
 
 ;; http://localhost:3000/#?anchor=fn.1
 ;; http://localhost:3000/#?anchor=fn.1
 (def routes
 (def routes
@@ -25,10 +28,6 @@
     {:name :repos
     {:name :repos
      :view repo/repos}]
      :view repo/repos}]
 
 
-   ["/whiteboard/:name"
-    {:name :whiteboard
-     :view whiteboard/whiteboard-route}]
-
    ["/whiteboards"
    ["/whiteboards"
     {:name :whiteboards
     {:name :whiteboards
      :view whiteboard/whiteboard-dashboard}]
      :view whiteboard/whiteboard-dashboard}]
@@ -37,17 +36,16 @@
     {:name :repo-add
     {:name :repo-add
      :view setups/picker}]
      :view setups/picker}]
 
 
-   ["/all-files"
-    {:name :all-files
-     :view file/files}]
-
-   ["/file/:path"
-    {:name :file
-     :view file/file}]
-
    ["/page/:name"
    ["/page/:name"
     {:name :page
     {:name :page
-     :view page/page}]
+     :view (fn [route-match]
+             (let [page-name (get-in route-match [:parameters :path :name])
+                   db (db/get-db)
+                   whiteboard? (when db
+                                 (ldb/whiteboard-page? (db/entity (ldb/get-first-page-by-name db page-name))))]
+               (if whiteboard?
+                 (whiteboard/whiteboard-route route-match)
+                 (page/page route-match))))}]
 
 
    ["/page/:name/block/:block-route-name"
    ["/page/:name/block/:block-route-name"
     {:name :page-block
     {:name :page-block
@@ -93,7 +91,15 @@
     {:name :user-login
     {:name :user-login
      :view login/page}]
      :view login/page}]
 
 
-   ["/ui"
-    {:name :ui
-     :view shui/page}]
-   ])
+   ["/all-files"
+    {:name :all-files
+     :view file/files}]
+
+   ["/file/:path"
+    {:name :file
+     :view file/file}]
+
+   (when config/dev?
+     ["/ui"
+      {:name :ui
+       :view shui/page}])])

+ 4 - 4
src/main/frontend/search.cljs

@@ -133,12 +133,12 @@
 
 
 (defn get-page-unlinked-refs
 (defn get-page-unlinked-refs
   "Get matched result from search first, and then filter by worker db"
   "Get matched result from search first, and then filter by worker db"
-  [page]
+  [page-id]
   (when-let [repo (state/get-current-repo)]
   (when-let [repo (state/get-current-repo)]
-    (p/let [page-name (util/safe-page-name-sanity-lc page)
-            page (db/entity [:block/name page-name])
+    (p/let [page (db/entity page-id)
             alias-names (conj (set (map util/safe-page-name-sanity-lc
             alias-names (conj (set (map util/safe-page-name-sanity-lc
-                                        (db/get-page-alias-names repo page-name))) page-name)
+                                     (db/get-page-alias-names repo page-id)))
+                              (:block/original-name page))
             q (string/join " " alias-names)
             q (string/join " " alias-names)
             result (block-search repo q {:limit 100})
             result (block-search repo q {:limit 100})
             eids (map (fn [b] [:block/uuid (:block/uuid b)]) result)
             eids (map (fn [b] [:block/uuid (:block/uuid b)]) result)

+ 1 - 1
src/main/frontend/worker/db/fix.cljs

@@ -161,7 +161,7 @@
                  :as _opts}]
                  :as _opts}]
   (let [db @conn
   (let [db @conn
         page (d/entity db page-id)]
         page (d/entity db page-id)]
-    (when-not (or (ldb/whiteboard-page? db page)
+    (when-not (or (ldb/whiteboard-page? page)
                   (ldb/hidden-page? page))
                   (ldb/hidden-page? page))
       (let [transact-opts (if replace-tx? {:replace? true} {})
       (let [transact-opts (if replace-tx? {:replace? true} {})
             *fix-tx-data (atom [])]
             *fix-tx-data (atom [])]

+ 8 - 10
src/main/frontend/worker/export.cljs

@@ -4,18 +4,16 @@
             [logseq.outliner.tree :as otree]
             [logseq.outliner.tree :as otree]
             [frontend.worker.file.core :as worker-file]
             [frontend.worker.file.core :as worker-file]
             [datascript.core :as d]
             [datascript.core :as d]
-            [logseq.common.util :as common-util]
             [logseq.graph-parser.property :as gp-property]))
             [logseq.graph-parser.property :as gp-property]))
 
 
 (defn block->content
 (defn block->content
   "Converts a block including its children (recursively) to plain-text."
   "Converts a block including its children (recursively) to plain-text."
-  [repo db root-block-uuid-or-page-name tree->file-opts context]
-  (let [root-block-uuid (or
-                         (and (uuid? root-block-uuid-or-page-name) root-block-uuid-or-page-name)
-                         (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc
-                                                                 root-block-uuid-or-page-name)])))
-        init-level (or (:init-level tree->file-opts)
-                       (if (uuid? root-block-uuid-or-page-name) 1 0))
+  [repo db root-block-uuid tree->file-opts context]
+  (assert (uuid? root-block-uuid))
+  (let [init-level (or (:init-level tree->file-opts)
+                       (if (ldb/page? (d/entity db [:block/uuid root-block-uuid]))
+                         0
+                         1))
         blocks (ldb/get-block-and-children repo db root-block-uuid)
         blocks (ldb/get-block-and-children repo db root-block-uuid)
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
     (worker-file/tree->file-content repo db tree
     (worker-file/tree->file-content repo db tree
@@ -54,7 +52,7 @@
                                        (safe-keywordize b'))) blocks))
                                        (safe-keywordize b'))) blocks))
                     children (if whiteboard?
                     children (if whiteboard?
                                blocks'
                                blocks'
-                               (otree/blocks->vec-tree repo db blocks' name))
+                               (otree/blocks->vec-tree repo db blocks' (:db/id page)))
                     page' (safe-keywordize page)]
                     page' (safe-keywordize page)]
                 (assoc page' :block/children children))))))
                 (assoc page' :block/children children))))))
 
 
@@ -64,4 +62,4 @@
        (map (fn [d]
        (map (fn [d]
               (let [e (d/entity db (:e d))]
               (let [e (d/entity db (:e d))]
                 [(:block/original-name e)
                 [(:block/original-name e)
-                 (block->content repo db (:v d) {} {})])))))
+                 (block->content repo db (:block/uuid e) {} {})])))))

+ 1 - 1
src/main/frontend/worker/file.cljs

@@ -79,7 +79,7 @@
                    (not whiteboard?))
                    (not whiteboard?))
             (dissoc-request! request-id)
             (dissoc-request! request-id)
             (let [tree-or-blocks (if whiteboard? blocks
             (let [tree-or-blocks (if whiteboard? blocks
-                                     (otree/blocks->vec-tree repo @conn blocks (:block/name page-block)))]
+                                     (otree/blocks->vec-tree repo @conn blocks (:db/id page-block)))]
               (if page-block
               (if page-block
                 (file/save-tree! repo conn page-block tree-or-blocks blocks-just-deleted? context request-id)
                 (file/save-tree! repo conn page-block tree-or-blocks blocks-just-deleted? context request-id)
                 (do
                 (do

+ 1 - 1
src/main/frontend/worker/file/core.cljs

@@ -132,7 +132,7 @@
     (let [format (name (get page-block :block/format (:preferred-format context)))
     (let [format (name (get page-block :block/format (:preferred-format context)))
           date-formatter (:date-formatter context)
           date-formatter (:date-formatter context)
           title (string/capitalize (:block/name page-block))
           title (string/capitalize (:block/name page-block))
-          whiteboard-page? (ldb/whiteboard-page? @conn page-block)
+          whiteboard-page? (ldb/whiteboard-page? page-block)
           format (if whiteboard-page? "edn" format)
           format (if whiteboard-page? "edn" format)
           journal-page? (worker-date/valid-journal-title? title date-formatter)
           journal-page? (worker-date/valid-journal-title? title date-formatter)
           journal-title (worker-date/normalize-journal-title title date-formatter)
           journal-title (worker-date/normalize-journal-title title date-formatter)

+ 5 - 4
src/main/frontend/worker/file/page_rename.cljs

@@ -6,7 +6,8 @@
             [clojure.walk :as walk]
             [clojure.walk :as walk]
             [clojure.string :as string]
             [clojure.string :as string]
             [datascript.core :as d]
             [datascript.core :as d]
-            [logseq.common.config :as common-config]))
+            [logseq.common.config :as common-config]
+            [logseq.db :as ldb]))
 
 
 (defn- replace-page-ref-aux
 (defn- replace-page-ref-aux
   "Unsanitized names"
   "Unsanitized names"
@@ -105,10 +106,10 @@
 
 
 (defn replace-page-ref
 (defn replace-page-ref
   "Unsanitized only"
   "Unsanitized only"
-  [db config old-original-name new-name]
+  [db config page new-name]
   ;; update all pages which have references to this page
   ;; update all pages which have references to this page
-  (let [page (d/entity db [:block/name (common-util/page-name-sanity-lc old-original-name)])
-        to-page (d/entity db [:block/name (common-util/page-name-sanity-lc new-name)])
+  (let [to-page (d/entity db (ldb/get-first-page-by-name db new-name))
+        old-original-name (:block/original-name page)
         blocks (:block/_refs (d/entity db (:db/id page)))
         blocks (:block/_refs (d/entity db (:db/id page)))
         tx       (->> (map (fn [{:block/keys [uuid content properties format] :as block}]
         tx       (->> (map (fn [{:block/keys [uuid content properties format] :as block}]
                              (let [content    (let [content' (replace-old-page! config content old-original-name new-name format)]
                              (let [content    (let [content' (replace-old-page! config content old-original-name new-name format)]

+ 12 - 39
src/main/frontend/worker/handler/page.cljs

@@ -7,7 +7,6 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [datascript.core :as d]
             [datascript.core :as d]
             [clojure.string :as string]
             [clojure.string :as string]
-            [frontend.worker.date :as date]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
             [logseq.common.config :as common-config]
             [logseq.common.config :as common-config]
@@ -78,42 +77,23 @@
              persist-op?         true}
              persist-op?         true}
       :as options}]
       :as options}]
   (let [date-formatter (common-config/get-date-formatter config)
   (let [date-formatter (common-config/get-date-formatter config)
-        split-namespace? (not (or (string/starts-with? title "hls__")
-                                  (date/valid-journal-title? date-formatter title)))
-
         [title page-name] (get-title-and-pagename title)
         [title page-name] (get-title-and-pagename title)
         with-uuid? (if (uuid? uuid) uuid true)
         with-uuid? (if (uuid? uuid) uuid true)
         result (when (ldb/page-empty? @conn page-name)
         result (when (ldb/page-empty? @conn page-name)
-                 (let [pages    (if split-namespace?
-                                  (common-util/split-namespace-pages title)
-                                  [title])
+                 (let [pages    [title]
                        format   (or format (common-config/get-preferred-format config))
                        format   (or format (common-config/get-preferred-format config))
                        pages    (map (fn [page]
                        pages    (map (fn [page]
-                             ;; only apply uuid to the deepest hierarchy of page to create if provided.
+                                       ;; only apply uuid to the deepest hierarchy of page to create if provided.
                                        (-> (gp-block/page-name->map page (if (= page title) with-uuid? true) @conn true date-formatter)
                                        (-> (gp-block/page-name->map page (if (= page title) with-uuid? true) @conn true date-formatter)
                                            (assoc :block/format format)))
                                            (assoc :block/format format)))
                                      pages)
                                      pages)
                        txs      (->> pages
                        txs      (->> pages
-                           ;; for namespace pages, only last page need properties
-                                     drop-last
                                      (mapcat #(build-page-tx repo conn config date-formatter format nil % {}))
                                      (mapcat #(build-page-tx repo conn config date-formatter format nil % {}))
                                      (remove nil?))
                                      (remove nil?))
-                       txs      (map-indexed (fn [i page]
-                                               (if (zero? i)
-                                                 page
-                                                 (assoc page :block/namespace
-                                                        [:block/uuid (:block/uuid (nth txs (dec i)))])))
-                                             txs)
                        page-txs (build-page-tx repo conn config date-formatter format properties (last pages) (select-keys options [:whiteboard? :class? :tags]))
                        page-txs (build-page-tx repo conn config date-formatter format properties (last pages) (select-keys options [:whiteboard? :class? :tags]))
-                       page-txs (if (seq txs)
-                                  (update page-txs 0
-                                          (fn [p]
-                                            (assoc p :block/namespace [:block/uuid (:block/uuid (last txs))])))
-                                  page-txs)
                        first-block-tx (when (and
                        first-block-tx (when (and
                                              create-first-block?
                                              create-first-block?
                                              (not (or whiteboard? class?))
                                              (not (or whiteboard? class?))
-                                             (ldb/page-empty? @conn (:db/id (d/entity @conn [:block/name page-name])))
                                              page-txs)
                                              page-txs)
                                         (let [page-id [:block/uuid (:block/uuid (first page-txs))]]
                                         (let [page-id [:block/uuid (:block/uuid (first page-txs))]]
                                           [(sqlite-util/block-with-timestamps
                                           [(sqlite-util/block-with-timestamps
@@ -201,12 +181,12 @@
 (defn delete!
 (defn delete!
   "Deletes a page. Returns true if able to delete page. If unable to delete,
   "Deletes a page. Returns true if able to delete page. If unable to delete,
   calls error-handler fn and returns false"
   calls error-handler fn and returns false"
-  [repo conn page-name & {:keys [persist-op? rename? error-handler]
+  [repo conn page-uuid & {:keys [persist-op? rename? error-handler]
                           :or {persist-op? true
                           :or {persist-op? true
                                error-handler (fn [{:keys [msg]}] (js/console.error msg))}}]
                                error-handler (fn [{:keys [msg]}] (js/console.error msg))}}]
-  (when (and repo page-name)
-    (let [page-name (common-util/page-name-sanity-lc page-name)
-          page (d/entity @conn [:block/name page-name])
+  (when (and repo page-uuid)
+    (let [page (d/entity @conn [:block/uuid page-uuid])
+          page-name (:block/name page)
           blocks (:block/_page page)
           blocks (:block/_page page)
           truncate-blocks-tx-data (mapv
           truncate-blocks-tx-data (mapv
                                    (fn [block]
                                    (fn [block]
@@ -229,19 +209,12 @@
                                  [[:db.fn/retractEntity [:file/path file-path]]])
                                  [[:db.fn/retractEntity [:file/path file-path]]])
               ;; if other page alias this pagename,
               ;; if other page alias this pagename,
               ;; then just remove some attrs of this entity instead of retractEntity
               ;; then just remove some attrs of this entity instead of retractEntity
-                delete-page-tx (cond
-                                 (or (and db-based? (not (:block/_namespace page)))
-                                     (not db-based?))
-                                 (if (and db-based? (ldb/get-alias-source-page @conn page-name))
-                                   (when-let [id (:db/id (d/entity @conn [:block/name page-name]))]
-                                     (mapv (fn [attribute]
-                                             [:db/retract id attribute])
-                                           db-schema/retract-page-attributes))
-                                   (concat (db-refs->page repo page)
-                                           [[:db.fn/retractEntity [:block/name page-name]]]))
-
-                                 :else
-                                 nil)
+                delete-page-tx (if (and db-based? (ldb/get-alias-source-page @conn page-name))
+                                 (mapv (fn [attribute]
+                                         [:db/retract (:db/id page) attribute])
+                                       db-schema/retract-page-attributes)
+                                 (concat (db-refs->page repo page)
+                                         [[:db.fn/retractEntity (:db/id page)]]))
                 tx-data (concat truncate-blocks-tx-data delete-page-tx delete-file-tx)]
                 tx-data (concat truncate-blocks-tx-data delete-page-tx delete-file-tx)]
 
 
             (ldb/transact! conn tx-data
             (ldb/transact! conn tx-data

+ 75 - 163
src/main/frontend/worker/handler/page/rename.cljs

@@ -1,41 +1,13 @@
 (ns frontend.worker.handler.page.rename
 (ns frontend.worker.handler.page.rename
   "Page rename"
   "Page rename"
-  (:require [logseq.outliner.core :as outliner-core]
-            [logseq.outliner.tree :as otree]
-            [frontend.worker.handler.page :as worker-page]
-            [datascript.core :as d]
+  (:require [datascript.core :as d]
             [medley.core :as medley]
             [medley.core :as medley]
             [clojure.string :as string]
             [clojure.string :as string]
-            [logseq.common.util.page-ref :as page-ref]
             [frontend.worker.file.util :as wfu]
             [frontend.worker.file.util :as wfu]
             [frontend.worker.file.page-rename :as page-rename]
             [frontend.worker.file.page-rename :as page-rename]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db :as ldb]
             [logseq.db :as ldb]
-            [logseq.common.util :as common-util]
-            [logseq.graph-parser.text :as text]))
-
-(defn rename-update-namespace!
-  "update :block/namespace of the renamed block"
-  [repo conn config page old-original-name new-name]
-  (let [old-namespace? (text/namespace-page? old-original-name)
-        new-namespace? (text/namespace-page? new-name)]
-    (cond
-      new-namespace?
-      ;; update namespace
-      (let [namespace (first (common-util/split-last "/" new-name))]
-        (when namespace
-          (worker-page/create! repo conn config namespace) ;; create parent page if not exist, creation of namespace ref is handled in `create!`
-          (let [namespace-block (d/entity @conn [:block/name (common-util/page-name-sanity-lc namespace)])
-                page-txs [{:db/id (:db/id page)
-                           :block/namespace (:db/id namespace-block)}]]
-            (ldb/transact! conn page-txs {:persist-op? true}))))
-
-      old-namespace?
-      ;; retract namespace
-      (ldb/transact! conn [[:db/retract (:db/id page) :block/namespace]] {:persist-op? true})
-
-      :else
-      nil)))
+            [logseq.common.util :as common-util]))
 
 
 (defn- replace-page-ref
 (defn- replace-page-ref
   "Replace from-page refs with to-page"
   "Replace from-page refs with to-page"
@@ -92,47 +64,48 @@
 
 
 (declare rename-page-aux)
 (declare rename-page-aux)
 
 
-(defn- based-merge-pages!
-  [repo conn config from-page-name to-page-name {:keys [old-name new-name]}]
-  (when (and (ldb/page-exists? @conn from-page-name)
-             (ldb/page-exists? @conn to-page-name)
-             (not= from-page-name to-page-name))
-    (let [db @conn
-          to-page (d/entity db [:block/name to-page-name])
-          to-id (:db/id to-page)
-          from-page (d/entity db [:block/name from-page-name])
-          from-id (:db/id from-page)
-          from-first-child (some->> (d/pull db '[*] from-id)
-                                    (outliner-core/block @conn)
-                                    (#(otree/-get-down % conn))
-                                    (outliner-core/get-data))
-          to-last-direct-child-id (ldb/get-block-last-direct-child-id db to-id)
-          db-based? (sqlite-util/db-based-graph? repo)
-          datoms (d/datoms @conn :avet :block/page from-id)
-          block-eids (mapv :e datoms)
-          blocks (d/pull-many db '[:db/id :block/page :block/refs :block/path-refs :block/left :block/parent] block-eids)
-          blocks-tx-data (map (fn [block]
-                                (let [id (:db/id block)]
-                                  (cond->
-                                   {:db/id id
-                                    :block/page {:db/id to-id}
-                                    :block/refs (rename-update-block-refs! (:block/refs block) from-id to-id)}
-
-                                    (and from-first-child (= id (:db/id from-first-child)))
-                                    (assoc :block/left {:db/id (or to-last-direct-child-id to-id)})
-
-                                    (= (:block/parent block) {:db/id from-id})
-                                    (assoc :block/parent {:db/id to-id})))) blocks)
-          replace-ref-tx-data (if db-based?
-                                (replace-page-ref from-page to-page)
-                                (page-rename/replace-page-ref db config from-page-name to-page-name))
-          tx-data (concat blocks-tx-data replace-ref-tx-data)]
-
-      (rename-page-aux repo conn config old-name new-name
-                       :merge? true
-                       :other-tx tx-data))
-
-    (worker-page/delete! repo conn from-page-name {:rename? true})))
+;; FIXME: bring it back, decouple this from page renaming though
+(comment
+  (defn merge-pages!
+   [repo conn config from-page to-page]
+   (let [from-page-name (:block/original-name from-page)
+         to-page-name (:block/original-name to-page)]
+     (when (and from-page to-page
+                (not= from-page-name to-page-name))
+       (let [db @conn
+             to-id (:db/id to-page)
+             from-id (:db/id from-page)
+             from-first-child (some->> (d/pull db '[*] from-id)
+                                       (outliner-core/block @conn)
+                                       (#(otree/-get-down % conn))
+                                       (outliner-core/get-data))
+             to-last-direct-child-id (ldb/get-block-last-direct-child-id db to-id)
+             db-based? (sqlite-util/db-based-graph? repo)
+             datoms (d/datoms @conn :avet :block/page from-id)
+             block-eids (mapv :e datoms)
+             blocks (d/pull-many db '[:db/id :block/page :block/refs :block/path-refs :block/left :block/parent] block-eids)
+             blocks-tx-data (map (fn [block]
+                                   (let [id (:db/id block)]
+                                     (cond->
+                                      {:db/id id
+                                       :block/page {:db/id to-id}
+                                       :block/refs (rename-update-block-refs! (:block/refs block) from-id to-id)}
+
+                                       (and from-first-child (= id (:db/id from-first-child)))
+                                       (assoc :block/left {:db/id (or to-last-direct-child-id to-id)})
+
+                                       (= (:block/parent block) {:db/id from-id})
+                                       (assoc :block/parent {:db/id to-id})))) blocks)
+             replace-ref-tx-data (if db-based?
+                                   (replace-page-ref from-page to-page)
+                                   (page-rename/replace-page-ref db config from-page to-page-name))
+             tx-data (concat blocks-tx-data replace-ref-tx-data)]
+
+         (rename-page-aux repo conn config from-page-name to-page-name
+                          :merge? true
+                          :other-tx tx-data)
+
+         (worker-page/delete! repo conn (:block/uuid from-page) {:rename? true}))))))
 
 
 (defn- compute-new-file-path
 (defn- compute-new-file-path
   "Construct the full path given old full path and the file sanitized body.
   "Construct the full path given old full path and the file sanitized body.
@@ -145,9 +118,8 @@
     (common-util/string-join-path parts)))
     (common-util/string-join-path parts)))
 
 
 (defn- update-file-tx
 (defn- update-file-tx
-  [db old-page-name new-page-name]
-  (let [page (d/entity db [:block/name old-page-name])
-        file (:block/file page)]
+  [page new-page-name]
+  (let [file (:block/file page)]
     (when (and file (not (:block/journal? page)))
     (when (and file (not (:block/journal? page)))
       (let [old-path (:file/path file)
       (let [old-path (:file/path file)
             new-file-name (wfu/file-name-sanity new-page-name) ;; w/o file extension
             new-file-name (wfu/file-name-sanity new-page-name) ;; w/o file extension
@@ -159,27 +131,24 @@
 
 
 (defn- rename-page-aux
 (defn- rename-page-aux
   "Only accepts unsanitized page names"
   "Only accepts unsanitized page names"
-  [repo conn config old-name new-name & {:keys [merge? other-tx]}]
+  [repo conn config page new-name & {:keys [merge? other-tx]}]
   (let [db                  @conn
   (let [db                  @conn
-        old-page-name       (common-util/page-name-sanity-lc old-name)
+        old-page-name       (:block/original-name page)
         new-page-name       (common-util/page-name-sanity-lc new-name)
         new-page-name       (common-util/page-name-sanity-lc new-name)
-        db-based?           (sqlite-util/db-based-graph? repo)
-        page                (d/pull @conn '[*] [:block/name old-page-name])]
+        db-based?           (sqlite-util/db-based-graph? repo)]
     (when (and repo page)
     (when (and repo page)
-      (let [old-original-name   (:block/original-name page)
-            page-txs            (when-not merge?
+      (let [page-txs            (when-not merge?
                                   [{:db/id               (:db/id page)
                                   [{:db/id               (:db/id page)
-                                    :block/uuid          (:block/uuid page)
                                     :block/name          new-page-name
                                     :block/name          new-page-name
                                     :block/original-name new-name}])
                                     :block/original-name new-name}])
-            {:keys [old-path new-path tx-data]} (update-file-tx db old-page-name new-name)
+            {:keys [old-path new-path tx-data]} (update-file-tx page new-name)
             txs (concat page-txs
             txs (concat page-txs
                         other-tx
                         other-tx
                         (when-not db-based?
                         (when-not db-based?
                           (->>
                           (->>
                            (concat
                            (concat
                             ;;  update page refes in block content when ref name changes
                             ;;  update page refes in block content when ref name changes
-                            (page-rename/replace-page-ref db config old-name new-name)
+                            (page-rename/replace-page-ref db config page new-name)
                             ;; update file path
                             ;; update file path
                             tx-data)
                             tx-data)
 
 
@@ -187,101 +156,44 @@
 
 
         (ldb/transact! conn txs {:outliner-op :rename-page
         (ldb/transact! conn txs {:outliner-op :rename-page
                                  :data (cond->
                                  :data (cond->
-                                        {:old-name old-name
+                                        {:old-name old-page-name
                                          :new-name new-name}
                                          :new-name new-name}
                                          (and old-path new-path)
                                          (and old-path new-path)
                                          (merge {:old-path old-path
                                          (merge {:old-path old-path
-                                                 :new-path new-path}))})
-
-        (rename-update-namespace! repo conn config page old-original-name new-name)))))
+                                                 :new-path new-path}))})))))
 
 
-(defn- rename-namespace-pages!
+(defn- rename-page!
   "Original names (unsanitized only)"
   "Original names (unsanitized only)"
-  [repo conn config old-name new-name]
-  (let [pages (ldb/get-namespace-pages @conn old-name {:db-graph? (sqlite-util/db-based-graph? repo)})
-        page (d/pull @conn '[*] [:block/name (common-util/page-name-sanity-lc old-name)])
-        pages (cons page pages)]
-    (doseq [{:block/keys [name original-name]} pages]
-      (let [old-page-title (or original-name name)
-            ;; only replace one time, for the case that the namespace is a sub-string of the sub-namespace page name
-            ;; Example: has pages [[work]] [[work/worklog]],
-            ;; we want to rename [[work/worklog]] to [[work1/worklog]] when rename [[work]] to [[work1]],
-            ;; but don't rename [[work/worklog]] to [[work1/work1log]]
-            new-page-title (common-util/replace-first-ignore-case old-page-title old-name new-name)]
-        (when (and old-page-title new-page-title)
-          (rename-page-aux repo conn config old-page-title new-page-title)
-          (println "Renamed " old-page-title " to " new-page-title))))))
-
-(defn- rename-nested-pages
-  "Unsanitized names only"
-  [repo conn config old-ns-name new-ns-name]
-  (let [nested-page-str (page-ref/->page-ref (common-util/page-name-sanity-lc old-ns-name))
-        ns-prefix-format-str (str page-ref/left-brackets "%s/")
-        ns-prefix       (common-util/format ns-prefix-format-str (common-util/page-name-sanity-lc old-ns-name))
-        nested-pages    (ldb/get-pages-by-name-partition @conn nested-page-str)
-        nested-pages-ns (ldb/get-pages-by-name-partition @conn ns-prefix)]
-    (when nested-pages
-      ;; rename page "[[obsidian]] is a tool" to "[[logseq]] is a tool"
-      (doseq [{:block/keys [name original-name]} nested-pages]
-        (let [old-page-title (or original-name name)
-              new-page-title (string/replace
-                              old-page-title
-                              (page-ref/->page-ref old-ns-name)
-                              (page-ref/->page-ref new-ns-name))]
-          (when (and old-page-title new-page-title)
-            (rename-page-aux repo conn config old-page-title new-page-title)
-            (println "Renamed " old-page-title " to " new-page-title)))))
-    (when nested-pages-ns
-      ;; rename page "[[obsidian/page1]] is a tool" to "[[logseq/page1]] is a tool"
-      (doseq [{:block/keys [name original-name]} nested-pages-ns]
-        (let [old-page-title (or original-name name)
-              new-page-title (string/replace
-                              old-page-title
-                              (common-util/format ns-prefix-format-str old-ns-name)
-                              (common-util/format ns-prefix-format-str new-ns-name))]
-          (when (and old-page-title new-page-title)
-            (rename-page-aux repo conn config old-page-title new-page-title)
-            (println "Renamed " old-page-title " to " new-page-title)))))))
+  [repo conn config page new-name]
+  (rename-page-aux repo conn config page new-name)
+  (println "Renamed " (:block/original-name page) " to " new-name))
 
 
 (defn rename!
 (defn rename!
-  [repo conn config old-name new-name & {:keys [persist-op?]
-                                         :or {persist-op? true}}]
+  [repo conn config page-uuid new-name & {:keys [persist-op?]
+                                          :or {persist-op? true}}]
   (let [db @conn
   (let [db @conn
-        old-name      (string/trim old-name)
+        page-e        (d/entity db [:block/uuid page-uuid])
+        old-name      (:block/original-name page-e)
         new-name      (string/trim new-name)
         new-name      (string/trim new-name)
         old-page-name (common-util/page-name-sanity-lc old-name)
         old-page-name (common-util/page-name-sanity-lc old-name)
-        page-e (d/entity db [:block/name old-page-name])
         new-page-name (common-util/page-name-sanity-lc new-name)
         new-page-name (common-util/page-name-sanity-lc new-name)
-        new-page-e (d/entity db [:block/name new-page-name])
+        new-page-exists? (some? (ldb/get-first-page-by-name db new-name))
         name-changed? (not= old-name new-name)]
         name-changed? (not= old-name new-name)]
     (cond
     (cond
-      (ldb/built-in? page-e)
-      :built-in-page
-
       (string/blank? new-name)
       (string/blank? new-name)
       :invalid-empty-name
       :invalid-empty-name
 
 
-      (and page-e new-page-e
-           (or (contains? (:block/type page-e) "whiteboard")
-               (contains? (:block/type new-page-e) "whiteboard")))
-      :merge-whiteboard-pages
+      new-page-exists?
+      :rename-page-exists
 
 
-      (and old-name new-name name-changed?)
-      (do
-        (cond
-          (= old-page-name new-page-name) ; case changed
-          (ldb/transact! conn
-                         [{:db/id (:db/id page-e)
-                           :block/original-name new-name}]
-                         {:persist-op? persist-op?
-                          :outliner-op :rename-page})
-
-          (and (not= old-page-name new-page-name)
-               (d/entity @conn [:block/name new-page-name])) ; merge page
-          (based-merge-pages! repo conn config old-page-name new-page-name {:old-name old-name
-                                                                            :new-name new-name
-                                                                            :persist-op? persist-op?})
+      (ldb/built-in? page-e)
+      :built-in-page
 
 
-          :else                          ; rename
-          (rename-namespace-pages! repo conn config old-name new-name))
-        (rename-nested-pages repo conn config old-name new-name)))))
+      (and old-name new-name name-changed?)
+      (if (= old-page-name new-page-name) ; case changed
+        (ldb/transact! conn
+                       [{:db/id (:db/id page-e)
+                         :block/original-name new-name}]
+                       {:persist-op? persist-op?
+                        :outliner-op :rename-page})
+        (rename-page! repo conn config page-e new-name)))))

+ 6 - 7
src/main/frontend/worker/rtc/core.cljs

@@ -476,7 +476,7 @@
 (defn- move-all-blocks-to-another-page
 (defn- move-all-blocks-to-another-page
   [repo conn from-page-name to-page-name]
   [repo conn from-page-name to-page-name]
   (let [blocks (ldb/get-page-blocks @conn from-page-name {})
   (let [blocks (ldb/get-page-blocks @conn from-page-name {})
-        target-page-block (d/entity @conn [:block/name to-page-name])]
+        target-page-block (d/entity @conn (ldb/get-first-page-by-name @conn to-page-name))]
     (when (and (seq blocks) target-page-block)
     (when (and (seq blocks) target-page-block)
       (outliner-tx/transact!
       (outliner-tx/transact!
        {:persist-op? true
        {:persist-op? true
@@ -512,7 +512,7 @@
   (let [config (worker-state/get-config repo)]
   (let [config (worker-state/get-config repo)]
     (doseq [{:keys [self page-name original-name] :as op-value} update-page-ops]
     (doseq [{:keys [self page-name original-name] :as op-value} update-page-ops]
       (let [old-page-original-name (:block/original-name (d/entity @conn [:block/uuid self]))
       (let [old-page-original-name (:block/original-name (d/entity @conn [:block/uuid self]))
-            exist-page (d/entity @conn [:block/name page-name])
+            exist-page (d/entity @conn (ldb/get-first-page-by-name @conn page-name))
             create-opts {:create-first-block? false
             create-opts {:create-first-block? false
                          :uuid self :persist-op? false}]
                          :uuid self :persist-op? false}]
         (cond
         (cond
@@ -521,7 +521,7 @@
           (and exist-page
           (and exist-page
                (not= (:block/uuid exist-page) self)
                (not= (:block/uuid exist-page) self)
                (empty-page? exist-page))
                (empty-page? exist-page))
-          (do (worker-page/delete! repo conn page-name {:persist-op? false})
+          (do (worker-page/delete! repo conn self {:persist-op? false})
               (worker-page/create! repo conn config original-name create-opts))
               (worker-page/create! repo conn config original-name create-opts))
 
 
           ;; same name but different uuid
           ;; same name but different uuid
@@ -531,14 +531,14 @@
           (and exist-page
           (and exist-page
                (not= (:block/uuid exist-page) self))
                (not= (:block/uuid exist-page) self))
           (let [conflict-page-name (common-util/format "%s-%s-CONFLICT" original-name (tc/to-long (t/now)))]
           (let [conflict-page-name (common-util/format "%s-%s-CONFLICT" original-name (tc/to-long (t/now)))]
-            (worker-page-rename/rename! repo conn config original-name conflict-page-name {:persist-op? false})
+            (worker-page-rename/rename! repo conn config self conflict-page-name {:persist-op? false})
             (worker-page/create! repo conn config original-name create-opts)
             (worker-page/create! repo conn config original-name create-opts)
             (move-all-blocks-to-another-page repo conn conflict-page-name original-name))
             (move-all-blocks-to-another-page repo conn conflict-page-name original-name))
 
 
           ;; a client-page has same uuid as remote but different page-names,
           ;; a client-page has same uuid as remote but different page-names,
           ;; then we need to rename the client-page to remote-page-name
           ;; then we need to rename the client-page to remote-page-name
           (and old-page-original-name (not= old-page-original-name original-name))
           (and old-page-original-name (not= old-page-original-name original-name))
-          (worker-page-rename/rename! repo conn config old-page-original-name original-name {:persist-op? false})
+          (worker-page-rename/rename! repo conn config self original-name {:persist-op? false})
 
 
           ;; no such page, name=remote-page-name, OR, uuid=remote-block-uuid
           ;; no such page, name=remote-page-name, OR, uuid=remote-block-uuid
           ;; just create-page
           ;; just create-page
@@ -550,8 +550,7 @@
 (defn apply-remote-remove-page-ops
 (defn apply-remote-remove-page-ops
   [repo conn remove-page-ops]
   [repo conn remove-page-ops]
   (doseq [op remove-page-ops]
   (doseq [op remove-page-ops]
-    (when-let [page-name (:block/name (d/entity @conn [:block/uuid (:block-uuid op)]))]
-      (worker-page/delete! repo conn page-name {:persist-op? false}))))
+    (worker-page/delete! repo conn (:block-uuid op) {:persist-op? false})))
 
 
 (defn filter-remote-data-by-local-unpushed-ops
 (defn filter-remote-data-by-local-unpushed-ops
   "when remote-data request client to move/update/remove/... blocks,
   "when remote-data request client to move/update/remove/... blocks,

+ 5 - 14
src/main/frontend/worker/search.cljs

@@ -9,7 +9,8 @@
             [frontend.search.fuzzy :as fuzzy]
             [frontend.search.fuzzy :as fuzzy]
             [frontend.worker.util :as worker-util]
             [frontend.worker.util :as worker-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.sqlite.util :as sqlite-util]
-            [logseq.common.util :as common-util]))
+            [logseq.common.util :as common-util]
+            [logseq.db :as ldb]))
 
 
 ;; TODO: use sqlite for fuzzy search
 ;; TODO: use sqlite for fuzzy search
 (defonce indices (atom nil))
 (defonce indices (atom nil))
@@ -225,18 +226,8 @@
 
 
 (defn whiteboard-page?
 (defn whiteboard-page?
   "Given a page name or a page object, check if it is a whiteboard page"
   "Given a page name or a page object, check if it is a whiteboard page"
-  [db page]
-  (cond
-    (string? page)
-    (let [page (d/entity db [:block/name page])]
-      (or
-       (= (:block/type page) "whiteboard")
-       (contains? (set (:block/type page)) "whiteboard")))
-
-    (seq page)
-    (contains? (set (:block/type page)) "whiteboard")
-
-    :else false))
+  [db uuid]
+  (ldb/whiteboard-page? (d/entity db [:block/uuid uuid])))
 
 
 (defn block->index
 (defn block->index
   "Convert a block to the index for searching"
   "Convert a block to the index for searching"
@@ -246,7 +237,7 @@
         block? (nil? name)
         block? (nil? name)
         db-based? (sqlite-util/db-based-graph? repo)]
         db-based? (sqlite-util/db-based-graph? repo)]
     (when-not (or
     (when-not (or
-               (and page? name (whiteboard-page? db name))
+               (and page? name (whiteboard-page? db uuid))
                (and block? (> (count content) 10000))
                (and block? (> (count content) 10000))
                (and (empty? properties)
                (and (empty? properties)
                     (or (and block? (string/blank? content))
                     (or (and block? (string/blank? content))

+ 19 - 17
src/main/logseq/api.cljs

@@ -49,7 +49,8 @@
             [frontend.modules.layout.core]
             [frontend.modules.layout.core]
             [frontend.handler.code :as code-handler]
             [frontend.handler.code :as code-handler]
             [frontend.handler.search :as search-handler]
             [frontend.handler.search :as search-handler]
-            [logseq.api.block :as api-block]))
+            [logseq.api.block :as api-block]
+            [logseq.db :as ldb]))
 
 
 ;; Alert: this namespace shouldn't invoke any reactive queries
 ;; Alert: this namespace shouldn't invoke any reactive queries
 
 
@@ -61,6 +62,7 @@
                 (and (vector? id-or-name) (= (count id-or-name) 2)) id-or-name
                 (and (vector? id-or-name) (= (count id-or-name) 2)) id-or-name
                 (number? id-or-name) id-or-name
                 (number? id-or-name) id-or-name
                 (and (string? id-or-name) (util/uuid-string? id-or-name)) [:block/uuid (uuid id-or-name)]
                 (and (string? id-or-name) (util/uuid-string? id-or-name)) [:block/uuid (uuid id-or-name)]
+                ;; Can still use block/name lookup ref here because the db_worker convert it to the actual eid
                 :else [:block/name (util/page-name-sanity-lc id-or-name)])]
                 :else [:block/name (util/page-name-sanity-lc id-or-name)])]
       (db-async/<pull (state/get-current-repo) eid))))
       (db-async/<pull (state/get-current-repo) eid))))
 
 
@@ -642,7 +644,8 @@
                                          [nil (uuid block-uuid-or-page-name)]
                                          [nil (uuid block-uuid-or-page-name)]
                                          [block-uuid-or-page-name nil])
                                          [block-uuid-or-page-name nil])
                 page-name              (when page-name (util/page-name-sanity-lc page-name))
                 page-name              (when page-name (util/page-name-sanity-lc page-name))
-                _                      (when (and page-name (not (db/entity [:block/name page-name])))
+                _                      (when (and page-name
+                                                  (nil? (ldb/get-first-page-by-name (db/get-db) page-name)))
                                          (page-handler/<create! block-uuid-or-page-name {:create-first-block? false}))
                                          (page-handler/<create! block-uuid-or-page-name {:create-first-block? false}))
                 custom-uuid            (or customUUID (:id properties))
                 custom-uuid            (or customUUID (:id properties))
                 custom-uuid            (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
                 custom-uuid            (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
@@ -816,8 +819,9 @@
 (def ^:export get_current_page_blocks_tree
 (def ^:export get_current_page_blocks_tree
   (fn []
   (fn []
     (when-let [page (state/get-current-page)]
     (when-let [page (state/get-current-page)]
-      (let [blocks (db-model/get-page-blocks-no-cache page)
-            blocks (outliner-tree/blocks->vec-tree blocks page)
+      (let [page-id (ldb/get-first-page-by-name (db/get-db) page)
+            blocks (db-model/get-page-blocks-no-cache page-id)
+            blocks (outliner-tree/blocks->vec-tree blocks page-id)
             ;; clean key
             ;; clean key
             blocks (sdk-utils/normalize-keyword-for-json blocks)]
             blocks (sdk-utils/normalize-keyword-for-json blocks)]
         (bean/->js blocks)))))
         (bean/->js blocks)))))
@@ -825,9 +829,9 @@
 (def ^:export get_page_blocks_tree
 (def ^:export get_page_blocks_tree
   (fn [id-or-page-name]
   (fn [id-or-page-name]
     (p/let [_ (<ensure-page-loaded id-or-page-name)]
     (p/let [_ (<ensure-page-loaded id-or-page-name)]
-      (when-let [page-name (:block/name (db-model/get-page id-or-page-name))]
-        (let [blocks (db-model/get-page-blocks-no-cache page-name)
-              blocks (outliner-tree/blocks->vec-tree blocks page-name)
+      (when-let [page-id (:db/id (db-model/get-page id-or-page-name))]
+        (let [blocks (db-model/get-page-blocks-no-cache page-id)
+              blocks (outliner-tree/blocks->vec-tree blocks page-id)
               blocks (sdk-utils/normalize-keyword-for-json blocks)]
               blocks (sdk-utils/normalize-keyword-for-json blocks)]
           (bean/->js blocks))))))
           (bean/->js blocks))))))
 
 
@@ -837,24 +841,22 @@
           block (db-async/<get-block repo page-name-or-uuid :children? false)
           block (db-async/<get-block repo page-name-or-uuid :children? false)
           ;; load refs to db
           ;; load refs to db
           _ (when-let [id (:db/id block)] (db-async/<get-block-refs repo id))
           _ (when-let [id (:db/id block)] (db-async/<get-block-refs repo id))
-          page-name (:block/name block)
-          ref-blocks (if page-name
-                       (db-model/get-page-referenced-blocks-full page-name)
-                       (db-model/get-block-referenced-blocks (:block/uuid block)))
+          page? (nil? (:block/page block))
+          ref-blocks (if page?
+                       (db-model/get-page-referenced-blocks-full (:db/id block))
+                       (db-model/get-block-referenced-blocks (:db/id block)))
           ref-blocks (and (seq ref-blocks) (into [] ref-blocks))]
           ref-blocks (and (seq ref-blocks) (into [] ref-blocks))]
     (bean/->js (sdk-utils/normalize-keyword-for-json ref-blocks))))
     (bean/->js (sdk-utils/normalize-keyword-for-json ref-blocks))))
 
 
 (defn ^:export get_pages_from_namespace
 (defn ^:export get_pages_from_namespace
   [ns]
   [ns]
-  (when-let [repo (and ns (state/get-current-repo))]
-    (when-let [pages (db-model/get-namespace-pages repo ns)]
-      (bean/->js (sdk-utils/normalize-keyword-for-json pages)))))
+  (when-let [_repo (and ns (state/get-current-repo))]
+    (bean/->js nil)))
 
 
 (defn ^:export get_pages_tree_from_namespace
 (defn ^:export get_pages_tree_from_namespace
   [ns]
   [ns]
-  (when-let [repo (and ns (state/get-current-repo))]
-    (when-let [pages (db-model/get-namespace-hierarchy repo ns)]
-      (bean/->js (sdk-utils/normalize-keyword-for-json pages)))))
+  (when-let [_repo (and ns (state/get-current-repo))]
+    (bean/->js nil)))
 
 
 (defn last-child-of-block
 (defn last-child-of-block
   [block]
   [block]

+ 1 - 1
src/test/frontend/db/db_based_model_test.cljs

@@ -57,7 +57,7 @@
       (is (= (model/get-class-objects repo (:db/id class))
       (is (= (model/get-class-objects repo (:db/id class))
              [(:db/id (db/entity [:block/uuid fbid]))]))
              [(:db/id (db/entity [:block/uuid fbid]))]))
 
 
-      (testing "namespace classes"
+      (testing "classes parent"
         (page-handler/create! "class2" opts)
         (page-handler/create! "class2" opts)
       ;; set class2's parent to class1
       ;; set class2's parent to class1
         (let [class2 (db/entity [:block/name "class2"])]
         (let [class2 (db/entity [:block/name "class2"])]

+ 0 - 51
src/test/frontend/db/model_test.cljs

@@ -9,32 +9,6 @@
 (use-fixtures :each {:before test-helper/start-test-db!
 (use-fixtures :each {:before test-helper/start-test-db!
                      :after test-helper/destroy-test-db!})
                      :after test-helper/destroy-test-db!})
 
 
-(deftest get-namespace-pages
-  (load-test-files [{:file/path "pages/a.b.c.md"
-                     :file/content "foo"}
-                    {:file/path "pages/b.c.md"
-                     :file/content "bar"}
-                    {:file/path "pages/b.d.md"
-                     :file/content "baz"}])
-
-  (is (= ["a/b" "a/b/c"]
-         (map :block/name (model/get-namespace-pages test-helper/test-db "a"))))
-
-  (is (= ["b/c" "b/d"]
-         (map :block/name (model/get-namespace-pages test-helper/test-db "b")))))
-
-(deftest get-page-namespace-routes
-  (load-test-files [{:file/path "pages/a.b.c.md"
-                     :file/content "foo"}
-                    {:file/path "pages/b.c.md"
-                     :file/content "bar"}
-                    {:file/path "pages/b.d.md"
-                     :file/content "baz"}])
-
-  (is (= '()
-         (map :block/name (model/get-page-namespace-routes test-helper/test-db "b/c")))
-      "Empty if page exists"))
-
 (deftest test-page-alias-with-multiple-alias
 (deftest test-page-alias-with-multiple-alias
   (load-test-files [{:file/path "aa.md"
   (load-test-files [{:file/path "aa.md"
                      :file/content "alias:: ab, ac"}
                      :file/content "alias:: ab, ac"}
@@ -99,31 +73,6 @@
          (map first (model/get-pages-that-mentioned-page test-helper/test-db "generic page" false)))
          (map first (model/get-pages-that-mentioned-page test-helper/test-db "generic page" false)))
       "Must be empty"))
       "Must be empty"))
 
 
-(deftest remove-links-for-each-level-of-the-namespaces
-  (load-test-files [{:file/path "pages/generic page.md"
-                     :file/content "tags:: [[one/two/tree]], one/two
-- link to ns [[one]]
-- link to page one [[page ONE]]"}])
-
-  (is (= '("one/two/tree" "page one")
-         (map second (model/get-pages-relation test-helper/test-db true)))
-      "(get-pages-relation) Must be only ns one/two/tree")
-
-  (is (= '("one/two/tree" "page one")
-         (map second (#'model/remove-nested-namespaces-link [["generic page" "one/two/tree"]
-                                                           ["generic page" "one/two"]
-                                                           ["generic page" "one"]
-                                                           ["generic page" "page one"]])))
-      "(model/remove-nested-namespaces-link) Must be only ns one/two/tree")
-
-  (is (= '("one/two/tree" "one/two" "one")
-         (#'model/get-parents-namespace-list "one/two/tree/four"))
-      "Must be one/two/tree one/two one")
-
-  (is (= '("one/two" "one")
-         (#'model/get-unnecessary-namespaces-name '("one/two/tree" "one" "one/two" "non nested tag" "non nested link")))
-      "Must be  one/two one"))
-
 (deftest entity-query-should-return-nil-if-id-not-exists
 (deftest entity-query-should-return-nil-if-id-not-exists
   (is (nil? (db/entity 1000000))))
   (is (nil? (db/entity 1000000))))
 
 

+ 0 - 15
src/test/frontend/db/query_dsl_test.cljs

@@ -412,21 +412,6 @@ tags: [[other]]
               (dsl-query "(page nope)")))
               (dsl-query "(page nope)")))
       "Correctly returns no results"))
       "Correctly returns no results"))
 
 
-(deftest namespace-queries
-  (load-test-files [{:file/path "pages/ns1.page1.md"
-                     :file/content "foo"}
-                    {:file/path "pages/ns1.page2.md"
-                     :file/content "bar"}
-                    {:file/path "pages/ns2.page1.md"
-                     :file/content "baz"}])
-
-  (is (= #{"ns1/page1" "ns1/page2"}
-         (set (map :block/name (dsl-query "(namespace ns1)")))))
-
-  (is (= #{}
-         (set (map :block/name (dsl-query "(namespace blarg)"))))
-      "Correctly returns no results"))
-
 (deftest empty-queries
 (deftest empty-queries
   (testing "nil or blank strings should be ignored"
   (testing "nil or blank strings should be ignored"
     (are [x] (nil? (dsl-query x))
     (are [x] (nil? (dsl-query x))

+ 39 - 65
src/test/frontend/worker/handler/page/rename_test.cljs

@@ -2,11 +2,8 @@
   (:require [clojure.test :refer [deftest is testing use-fixtures]]
   (:require [clojure.test :refer [deftest is testing use-fixtures]]
             [frontend.test.helper :as test-helper]
             [frontend.test.helper :as test-helper]
             [datascript.core :as d]
             [datascript.core :as d]
-            [frontend.handler.page :as page-handler]
             [frontend.db :as db]
             [frontend.db :as db]
-            [frontend.worker.db.fix :as db-fix]
-            [frontend.worker.handler.page.rename :as worker-page-rename]
-            [frontend.handler.editor :as editor-handler]))
+            [frontend.worker.handler.page.rename :as worker-page-rename]))
 
 
 ;; FIXME: merge properties from both pages
 ;; FIXME: merge properties from both pages
 
 
@@ -43,66 +40,43 @@
         (is (= "New name" (:block/original-name entity)))
         (is (= "New name" (:block/original-name entity)))
         (is (= (:db/id page) (:db/id entity))))))
         (is (= (:db/id page) (:db/id entity))))))
 
 
-  (testing "Merge existing page"
-    (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
-    (page-rename "New name" "Existing page")
-    (let [e1 (db/entity [:block/name "new name"])
-          e2 (db/entity [:block/name "existing page"])]
-      ;; Old page deleted
-      (is (nil? e1))
-      ;; Blocks from both pages have been merged
-      (is (= (count (:block/_page e2)) (+ 1 (dec (count init-data)))))
-      ;; Ensure there's no conflicts
-      (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2)))))))
+  ;; (testing "Merge existing page"
+  ;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
+  ;;   (page-rename "New name" "Existing page")
+  ;;   (let [e1 (db/entity [:block/name "new name"])
+  ;;         e2 (db/entity [:block/name "existing page"])]
+  ;;     ;; Old page deleted
+  ;;     (is (nil? e1))
+  ;;     ;; Blocks from both pages have been merged
+  ;;     (is (= (count (:block/_page e2)) (+ 1 (dec (count init-data)))))
+  ;;     ;; Ensure there's no conflicts
+  ;;     (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))))
+  )
 
 
-(deftest merge-with-empty-page
-  (page-handler/create! "Existing page" {:redirect? false :create-first-block? false})
-  (page-rename "Test" "Existing page")
-  (let [e1 (db/entity [:block/name "test"])
-        e2 (db/entity [:block/name "existing page"])]
-      ;; Old page deleted
-    (is (nil? e1))
-      ;; Blocks from both pages have been merged
-    (is (= (count (:block/_page e2)) (dec (count init-data))))
-      ;; Ensure there's no conflicts
-    (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))))
+;; (deftest merge-with-empty-page
+;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? false})
+;;   (page-rename "Test" "Existing page")
+;;   (let [e1 (db/entity [:block/name "test"])
+;;         e2 (db/entity [:block/name "existing page"])]
+;;       ;; Old page deleted
+;;     (is (nil? e1))
+;;       ;; Blocks from both pages have been merged
+;;     (is (= (count (:block/_page e2)) (dec (count init-data))))
+;;       ;; Ensure there's no conflicts
+;;     (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))))
 
 
-(deftest rename-a-page-to-existing-whiteboard
-  (testing "Renaming a page to an existing whiteboard page"
-    (page-handler/create! "Whiteboard page" {:redirect? false
-                                             :whiteboard? true})
-    (is (= :merge-whiteboard-pages (page-rename "Test" "Whiteboard page")))
-    (is (= :merge-whiteboard-pages (page-rename "Whiteboard page" "Test")))))
-
-(deftest merge-existing-pages-should-update-ref-ids
-  (testing "Merge existing page"
-    (editor-handler/save-block! repo fbid "Block 1 [[Test]]")
-    (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
-    (page-rename "Test" "Existing page")
-    (let [e1 (db/entity [:block/name "test"])
-          e2 (db/entity [:block/name "existing page"])]
-      ;; Old page deleted
-      (is (nil? e1))
-      ;; Blocks from both pages have been merged
-      (is (= (count (:block/_page e2)) (+ 1 (dec (count init-data)))))
-      ;; Ensure there's no conflicts
-      (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))
-      ;; Content updated
-      (is (= "Block 1 [[Existing page]]" (:block/content (db/entity [:block/uuid fbid])))))))
-
-;; TODO: full coverage
-(deftest rename-namespace-pages
-  (testing "Rename a page to a namespaced one"
-    (page-rename "Test" "Abc/Def Ghi/Jk")
-    (let [e1 (db/entity [:block/name "test"])
-          e2 (db/entity [:block/name "abc/def ghi/jk"])
-          e3 (db/entity [:block/name "abc/def ghi"])
-          e4 (db/entity [:block/name "abc"])]
-      ;; Old page deleted
-      (is (nil? e1))
-      ;; Blocks from both pages have been merged
-      (is (= (count (:block/_page e2)) (dec (count init-data))))
-      ;; Ensure there's no conflicts
-      (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))
-      (is (= (:db/id e3) (:db/id (:block/namespace e2))))
-      (is (= (:db/id e4) (:db/id (:block/namespace e3)))))))
+;; (deftest merge-existing-pages-should-update-ref-ids
+;;   (testing "Merge existing page"
+;;     (editor-handler/save-block! repo fbid "Block 1 [[Test]]")
+;;     (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
+;;     (page-rename "Test" "Existing page")
+;;     (let [e1 (db/entity [:block/name "test"])
+;;           e2 (db/entity [:block/name "existing page"])]
+;;       ;; Old page deleted
+;;       (is (nil? e1))
+;;       ;; Blocks from both pages have been merged
+;;       (is (= (count (:block/_page e2)) (+ 1 (dec (count init-data)))))
+;;       ;; Ensure there's no conflicts
+;;       (is (empty? (db-fix/get-conflicts (db/get-db) (:db/id e2))))
+;;       ;; Content updated
+;;       (is (= "Block 1 [[Existing page]]" (:block/content (db/entity [:block/uuid fbid])))))))

+ 1 - 8
src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs

@@ -73,11 +73,4 @@
         [(d/entity @conn [:block/uuid uuid1])]
         [(d/entity @conn [:block/uuid uuid1])]
         opts))
         opts))
       (let [ops (gen-ops-fn)]
       (let [ops (gen-ops-fn)]
-        (is (contains? (set ops) [:remove {:block-uuids [uuid1]}]))))
-
-    (testing "create 'aaa/bbb/ccc' namespace-page"
-      (let [page-uuid (random-uuid)]
-        (page-handler/create! "aaa/bbb/ccc" {:redirect? false :create-first-block? false :uuid page-uuid})
-        (let [ops (gen-ops-fn)]
-          (is (= #{[:update-page "aaa"] [:update-page "aaa/bbb"] [:update-page "aaa/bbb/ccc"]}
-                 (set (map (juxt first (comp :page-name second)) ops)))))))))
+        (is (contains? (set ops) [:remove {:block-uuids [uuid1]}]))))))

+ 0 - 29
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -435,35 +435,6 @@ server: ;; remove 2
         (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
         (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
         (is (= (str page1-uuid "-rename") (:block/name (d/entity @conn [:block/uuid page1-uuid]))))))
         (is (= (str page1-uuid "-rename") (:block/name (d/entity @conn [:block/uuid page1-uuid]))))))
 
 
-    ;; TODO: add this test back when fixed
-    ;; (testing "apply-remote-update-page-ops-test3: create namespace-page"
-    ;;   (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
-    ;;                       :affected-blocks
-    ;;                       {page2-uuid {:op :update-page
-    ;;                                    :self page2-uuid
-    ;;                                    :page-name "aaa/bbb/ccc"
-    ;;                                    :original-name "aaa/bbb/ccc"}
-    ;;                        page3-uuid {:op :update-page
-    ;;                                    :self page3-uuid
-    ;;                                    :page-name "aaa/bbb"
-    ;;                                    :original-name "aaa/bbb"}
-    ;;                        page4-uuid {:op :update-page
-    ;;                                    :self page4-uuid
-    ;;                                    :page-name "aaa"
-    ;;                                    :original-name "aaa"}}}
-    ;;         update-page-ops (vals
-    ;;                          (:update-page-ops-map
-    ;;                           (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
-    ;;     (is (rtc-const/data-from-ws-validator data-from-ws))
-    ;;     (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
-    ;;     (prn ::x
-    ;;          (into {} (d/entity @conn [:block/uuid page2-uuid]))
-    ;;          (into {} (d/entity @conn [:block/uuid page3-uuid]))
-    ;;          (into {} (d/entity @conn [:block/uuid page4-uuid]))
-    ;;          (into {} (d/entity @conn [:block/name "aaa"]))
-    ;;          (into {} (d/entity @conn [:block/name "aaa/bbb"]))
-    ;;          (into {} (d/entity @conn [:block/name "aaa/bbb/ccc"])))
-    ;;     ))
     (testing "apply-remote-remove-page-ops-test1"
     (testing "apply-remote-remove-page-ops-test1"
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
                           :affected-blocks
                           :affected-blocks