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]
             [logseq.db.frontend.rules :as rules]
             [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
 (def block-attrs
@@ -107,34 +108,19 @@
           (->> (map #(db-content/update-block-content repo db % (:db/id %))))))
 
 (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
   "Return blocks of the designated page, without using cache.
    page - name / title of the page"
-  [db page {:keys [pull-keys]
+  [db page-id {:keys [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
   [db page-id]
@@ -217,7 +203,7 @@
                                     (= 1 (count children))
                                     (contains? #{"" "-" "*"} (string/trim (:block/content first-child))))))
                                 (not (contains? built-in-pages name))
-                                (not (whiteboard-page? db page))
+                                (not (whiteboard-page? page))
                                 (not (:block/_namespace page))
                                 (not (contains? (:block/type page) "property"))
                                  ;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility)
@@ -409,38 +395,6 @@
     (when (seq 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
   "Get a page given its unsanitized name"
   [db page-name]
@@ -547,6 +501,14 @@
   [db]
   (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
   (defn db-based-graph?
     "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/type {:optional true} [:enum #{"class"} #{"property"} #{"whiteboard"} #{"hidden"}]]
    [:block/journal? :boolean]
-   [:block/namespace {:optional true} :int]
    [:block/alias {:optional true} [:set :int]]
     ;; TODO: Should this be here or in common?
    [: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
   "Builds a hidden property page for closed values to be transacted"
   [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)
         (assoc :block/type #{"hidden"}
                :block/format :markdown))))

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

@@ -4,14 +4,7 @@
 (def ^:large-vars/data-var rules
   "Rules used mainly in frontend.db.model"
   ;; 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)
       [?c :class/parent ?p]]
      [(class-parent ?p ?c)
@@ -128,11 +121,6 @@
      [?b :block/page ?bp]
      [?bp :block/name ?page-name]]
 
-   :namespace
-   '[(namespace ?p ?namespace)
-     [?p :block/namespace ?parent]
-     [?parent :block/name ?namespace]]
-
    :property
    '[(property ?b ?key ?val)
      [?b :block/properties ?prop]

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

@@ -24,7 +24,7 @@
                   :db/index true}
    :block/left   {:db/valueType :db.type/ref
                   :db/index true}
-   :block/collapsed? {:db/index true}
+   :block/collapsed? {}
    :block/collapsed-properties {:db/valueType :db.type/ref
                                 :db/cardinality :db.cardinality/many}
 
@@ -98,8 +98,6 @@
    ;; whether page's is a journal
    :block/journal? {}
    :block/journal-day {}
-   ;; page's namespace
-   :block/namespace {:db/valueType :db.type/ref}
 
    ;; block's file
    :block/file {:db/valueType :db.type/ref}
@@ -124,7 +122,8 @@
    (dissoc schema
            :block/properties :block/properties-text-values :block/pre-block? :recent/pages :file/handle :block/file
            :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}
     :file/last-modified-at {}
     :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.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
   (defn- get-built-in-files
     [db]
@@ -62,11 +71,10 @@
   (assoc b :block.temp/fully-loaded? true))
 
 (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]
                        (let [long-page? (> (count children) 500)]
                          (if long-page?
@@ -76,16 +84,16 @@
                            (->> (d/pull-many db '[*] (map :db/id children))
                                 (map #(with-block-refs db %))
                                 (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->
          {:block (->> (d/pull db '[*] (:db/id block))
                       (with-tags db)
@@ -125,7 +133,8 @@
 (defn get-favorites
   "Favorites page and its blocks"
   [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
       (concat [block]
               (->> (keep :block/link children)
@@ -135,7 +144,8 @@
 
 (defn get-full-page-and-blocks
   [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))]
     (cons (:block result)
           (map #(dissoc % :children) (:children result)))))

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

@@ -23,12 +23,11 @@
   [db file-path]
   (ffirst
    (d/q
-    '[:find ?page-name
+    '[:find ?page
       :in $ ?path
       :where
       [?file :file/path ?path]
-      [?page :block/file ?file]
-      [?page :block/original-name ?page-name]]
+      [?page :block/file ?file]]
     db
     file-path)))
 
@@ -50,9 +49,9 @@
   UUIDs."
   [db file-page file-path retain-uuid-blocks]
   (let [existing-file-page (get-file-page db file-path)
-        pages-to-clear (distinct (filter some? [existing-file-page (:block/name file-page)]))
-        blocks (mapcat (fn [page]
-                         (ldb/get-page-blocks db page {:pull-keys [:db/id :block/uuid]}))
+        pages-to-clear (distinct (filter some? [existing-file-page (:db/id file-page)]))
+        blocks (mapcat (fn [page-id]
+                         (ldb/get-page-blocks db page-id {:pull-keys [:db/id :block/uuid]}))
                        pages-to-clear)
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
     (retract-blocks-tx (distinct blocks) retain-uuids)))

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

@@ -292,8 +292,6 @@
     (and original-page-name (string? original-page-name))
     (let [original-page-name (common-util/remove-boundary-slashes original-page-name)
           [original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)
-          namespace? (and (not (boolean (text/get-nested-page-name original-page-name)))
-                          (text/namespace-page? original-page-name))
           page-entity (some-> db (d/entity [:block/name page-name]))
           original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
       (merge
@@ -305,10 +303,6 @@
                                (uuid? with-id?) with-id?)
                          (d/squuid))]
            {:block/uuid new-uuid}))
-       (when namespace?
-         (let [namespace (first (common-util/split-last "/" original-page-name))]
-           (when-not (string/blank? namespace)
-             {:block/namespace {:block/name (common-util/page-name-sanity-lc namespace)}})))
        (when (and with-timestamp? (not page-entity)) ;; Only assign timestamp on creating new entity
          (let [current-ms (common-util/time-ms)]
            {:block/created-at current-ms
@@ -353,19 +347,7 @@
     (let [*name->id (atom {})
           ref->map-fn (fn [*col _tag?]
                         (let [col (remove string/blank? @*col)
-                              children-pages (->> (mapcat (fn [p]
-                                                            (let [p (if (map? p)
-                                                                      (:block/original-name p)
-                                                                      p)]
-                                                              (when (string? p)
-                                                                (let [p (or (text/get-nested-page-name p) p)]
-                                                                  (when (text/namespace-page? p)
-                                                                    (common-util/split-namespace-pages p))))))
-                                                          col)
-                                                  (remove string/blank?)
-                                                  (distinct))
-                              col (->> (distinct (concat col children-pages))
-                                       (remove nil?))]
+                              col (distinct col)]
                           (map
                            (fn [item]
                              (let [macro? (and (map? item)

+ 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
                                 disallowed-attributes [:block/name :block/uuid :block/format :block/journal? :block/original-name :block/journal-day
                                                        :block/created-at :block/updated-at]
-                                allowed-attributes [:block/properties :block/tags :block/alias :block/namespace :class/parent :block/type]
+                                allowed-attributes [:block/properties :block/tags :block/alias :class/parent :block/type]
                                 block-changes (select-keys % allowed-attributes)]
                             (when-let [ignored-attrs (not-empty (apply dissoc % (into disallowed-attributes allowed-attributes)))]
                               (notify-user {:msg (str "Import ignored the following attributes on page " (pr-str (:block/original-name %)) ": "

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

@@ -251,16 +251,9 @@
              (:block/properties-text-values (first blocks))]
             [properties [] {}])
           page-map (build-page-map properties invalid-properties properties-text-values file page page-name (assoc options' :from-page page))
-          namespace-pages (let [page (:block/original-name page-map)]
-                            (when (text/namespace-page? page)
-                              (->> (common-util/split-namespace-pages page)
-                                   (map (fn [page]
-                                          (-> (gp-block/page-name->map page true db true date-formatter)
-                                              (assoc :block/format format)))))))
           pages (->> (concat
                       [page-map]
-                      @ref-pages
-                      namespace-pages)
+                      @ref-pages)
                      ;; remove block references
                      (remove vector?)
                      (remove nil?))

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

@@ -133,19 +133,6 @@
            (get-counts-for-common-attributes db))
         "Counts for blocks with common block attributes")
 
-    (let [no-name (->> (d/q '[:find (pull ?n [*]) :where [?b :block/namespace ?n]] db)
-                       (filter (fn [x]
-                                 (when-not (:block/original-name (first x))
-                                   x))))
-          all-namespaces (->> (d/q '[:find (pull ?n [*]) :where [?b :block/namespace ?n]] db)
-                              (map (comp :block/original-name first))
-                              set)]
-      (is (= #{"term" "setting" "book" "templates" "Query table" "page"
-               "Whiteboard" "Whiteboard/Tool" "Whiteboard/Tool/Shape" "Whiteboard/Object"
-               "Whiteboard/Property" "Community" "Tweet"}
-             all-namespaces)
-          (str "Has correct namespaces: " no-name)))
-
     (is (empty? (->> (d/q '[:find ?n :where [?b :block/name ?n]] db)
                      (map first)
                      (filter #(string/includes? % "___"))))

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

@@ -47,14 +47,6 @@
        :else
        (remove-level-space-aux! text block-pattern space? trim-left?)))))
 
-(defn namespace-page?
-  [page-name]
-  (and (string? page-name)
-       (string/includes? page-name "/")
-       (not (string/starts-with? page-name "../"))
-       (not (string/starts-with? page-name "./"))
-       (not (common-util/url? page-name))))
-
 (defn parse-non-string-property-value
   "Return parsed non-string property value or nil if none is found"
   [v]

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

@@ -42,16 +42,31 @@
 
 (defn- get-root-and-page
   [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)]
       [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]))
 
 (defn blocks->vec-tree
   "`blocks` need to be in the same page."
   [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
       blocks
       (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.graph-parser :as graph-parser]
             [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!
   (let [conn (gp-db/start-conn)
@@ -56,8 +57,8 @@
         "Contains all pages that have been marked public")
     (is (not (contains? exported-pages "page1"))
         "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)
         "Only exports blocks from public pages")
     (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
                          ;; Open new page if the page does not exist
                          (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)))
 
                        block-id
                        (if-let [block (db-model/get-block-by-uuid block-id)]
                          (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))
                          (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-page?
-        (route-handler/redirect-to-whiteboard! page-name)
+        (route-handler/redirect-to-page! page-name)
 
         (nil? page)
         (state/pub-event! [:page/create page-name-in-block])
@@ -575,7 +575,7 @@
                (and tag? display-close-button?) (str " pl-4"))
       :data-ref page-name
       :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-leave #(reset! *hover? false)
       :on-pointer-down (fn [e]
@@ -958,8 +958,8 @@
                           ;; pdf annotation
                         [: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
                         :else (route-handler/redirect-to-page! id))))))}
@@ -1486,27 +1486,6 @@
           format (get-in config [:block :block/format] :markdown)]
       (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
   [config options]
   (let [{:keys [name arguments]} options
@@ -1525,11 +1504,7 @@
       (macro-function-cp config arguments)
 
       (= 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")
       (when-let [url (first arguments)]
@@ -1727,7 +1702,7 @@
       (state/conj-selection-block! (gdom/getElement block-id) :down)
       (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")
             "block-dom-id"
             block-id)
@@ -1738,7 +1713,7 @@
   [e block uuid]
   (cond
     (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")
     (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)])
           original-name (:block/original-name page)]
       (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)))
     (state/close-modal!)))
 
@@ -425,7 +425,7 @@
            (let [page-name (:block/name page)]
              (cond
                (= (: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)
                (route-handler/redirect-to-page! block-id)
                :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)
         ctx-icon #(shui/tabler-icon %1 {:class "scale-90 pr-1 opacity-80"})
         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/get-current-repo)
-                             (:db/id page-entity)
-                             :page))
+                            (state/get-current-repo)
+                            (:db/id page-entity)
+                            :page))
         x-menu-content (fn []
                          (let [x-menu-item shui/dropdown-menu-item
                                x-menu-shortcut shui/dropdown-menu-shortcut]
                            [:<>
                             (when-not recent?
                               (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
-                                                    (config/get-repo-fpath (state/get-current-repo) file-rpath))]
+                                                       (config/get-repo-fpath (state/get-current-repo) file-rpath))]
                               [:<>
                                (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
-                                 {: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
-                              {: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
     [:a.flex.items-center.justify-between.relative.group
@@ -126,32 +126,30 @@
         (let [name (if (empty? source-page) name (:block/name source-page))]
           (if (gobj/get e "shiftKey")
             (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]
                          (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))}
      [:span.page-icon.ml-3.justify-center (if whiteboard-page? (ui/icon "whiteboard" {:extension? true}) icon)]
      [:span.page-title {:class (when untitled? "opacity-50")}
       (if untitled? (t :untitled)
-                    (pdf-utils/fix-local-asset-pagename original-name))]
+          (pdf-utils/fix-local-asset-pagename original-name))]
 
      ;; dots trigger
      (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
 
@@ -203,7 +201,7 @@
            {:key name
             :title name
             :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}
            (page-name name (icon/get-page-icon entity {}) true)]))])))
 
@@ -838,7 +836,7 @@
                   block-el (.closest target ".bullet-container[blockid]")
                   block-id (some-> block-el (.getAttribute "blockid"))
                   {: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!
                     (fn [content]
@@ -851,7 +849,7 @@
                     (cond
                       page
                       (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))
 
                       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'] {

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

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

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

@@ -29,7 +29,8 @@
             [promesa.core :as p]
             [react-draggable]
             [rum.core :as rum]
-            [frontend.config :as config]))
+            [frontend.config :as config]
+            [logseq.db :as ldb]))
 
 (rum/defc commands < rum/reactive
   [id format]
@@ -108,16 +109,16 @@
                         (common-util/safe-subs value (+ (count q) 4 pos)))]
         (state/set-edit-content! (.-id input) value')
         (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
                                                                      :create-first-block? false}))
+                page' (db/entity (ldb/get-first-page-by-name (db/get-db) chosen-item))
                 current-block (state/get-edit-block)]
           (editor-handler/api-insert-new-block! chosen-item
                                                 {:block-uuid (:block/uuid current-block)
                                                  :sibling? 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)))
 
 (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-other-options state) (state/get-export-block-text-other-options))
                  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
         *text-other-options (::text-other-options state)
         *text-remove-options (::text-remove-options state)
@@ -157,21 +157,21 @@
          (ui/button "Text"
            :class "mr-4 w-20"
            :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"
            :class "mr-4 w-20"
            :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"
            :class "mr-4 w-20"
            :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"
              :class "w-20"
              :on-click #(do (reset! *export-block-type :png)
                             (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)
         [:div.flex.items-center.justify-center.relative
@@ -186,7 +186,7 @@
          (ui/checkbox {:class "mr-2 ml-4"
                        :on-change (fn [e]
                                     (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
                         (mapv (fn [opt]
                                 (if (= @*text-indent-style (:label opt))
@@ -202,7 +202,7 @@
                                 (let [value (util/evalue e)]
                                   (state/set-export-block-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]
                     [:option (cond->
                                {:key label
@@ -217,7 +217,7 @@
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :page-ref)
                                        (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")}}
              "[[text]] -> text"]
 
@@ -227,7 +227,7 @@
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :emphasis)
                                        (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")}}
              "remove emphasis"]
@@ -238,7 +238,7 @@
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :tag)
                                        (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")}}
              "remove #tags"]]
@@ -251,7 +251,7 @@
                                        (state/update-export-block-text-other-options!
                                          :newline-after-block (boolean (util/echecked? e)))
                                        (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")}}
              "newline after block"]
 
@@ -261,7 +261,7 @@
                           :on-change (fn [e]
                                        (state/update-export-block-text-remove-options! e :property)
                                        (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")}}
              "remove properties"]]
 
@@ -276,7 +276,7 @@
                                  level (if (= "all" value) :all (util/safe-parse-int value))]
                              (state/update-export-block-text-other-options! :keep-only-level<=N level)
                              (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))]
                [:option {:key n :value n} n])]]]))
 
@@ -290,8 +290,8 @@
                          (util/copy-to-clipboard! @*content :html (when (= tp :html) @*content)))
                        (reset! *copied? true)))
          (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))
                                         (t/now))]
                         (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.content :as content]
             [frontend.components.editor :as editor]
-            [frontend.components.hierarchy :as hierarchy]
             [frontend.components.plugins :as plugins]
             [frontend.components.query :as query]
             [frontend.components.reference :as reference]
@@ -235,13 +234,10 @@
 (rum/defc page-title-editor < rum/reactive
   [page {:keys [*input-value *title-value *edit? untitled? page-name old-name whiteboard-page?]}]
   (let [input-ref (rum/create-ref)
-        title (:block/original-name page)
         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)]
                        (reset! *title-value old-name)
                        (gobj/set (rum/deref input-ref) "value" old-name)
@@ -269,8 +265,8 @@
 
                     :else
                     (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))]
     [:input.edit-input.p-0.focus:outline-none.ring-none
      {:type          "text"
@@ -348,7 +344,8 @@
             {:class (when-not whiteboard-page? "title")
              :on-pointer-down (fn [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]
                          (when-not (= (.-nodeName (.-target e)) "INPUT")
                            (.preventDefault e)
@@ -553,19 +550,15 @@
                  (when page
                    [:div {:key "page-references"}
                     (rum/with-key
-                      (reference/references route-page-name)
+                      (reference/references page)
                       (str route-page-name "-refs"))]))
 
                (when (contains? (:block/type page) "class")
                  (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?)
                  [:div {:key "page-unlinked-references"}
-                  (reference/unlinked-references route-page-name)])])))))))
+                  (reference/unlinked-references page)])])))))))
 
 (rum/defcs page < rum/static
   [state option]
@@ -1041,20 +1034,21 @@
 
      [:div.pt-6.flex.justify-end.gap-4
       (ui/button
-        (t :cancel)
-        :theme :gray
-        :on-click close-fn)
+       (t :cancel)
+       :theme :gray
+       :on-click close-fn)
 
       (ui/button
        (t :yes)
        :on-click (fn []
                    (close-fn)
                    (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
                                                                      (fn []
-                                                                       (swap! failed-pages conj page-name))})) (map :block/name pages)))]
+                                                                       (swap! failed-pages conj (:block/name page)))}))
+                                        pages))]
                        (if (seq @failed-pages)
                          (notification/show! (t :all-pages/failed-to-delete-pages (string/join ", " (map pr-str @failed-pages)))
                                              :warning false)

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

@@ -21,37 +21,33 @@
             [logseq.common.path :as path]))
 
 (defn- delete-page!
-  [page-name]
-  (page-handler/<delete! page-name
+  [page]
+  (page-handler/<delete! (:block/uuid page)
                         (fn []
-                          (notification/show! (str "Page " page-name " was deleted successfully!")
+                          (notification/show! (str "Page " (:block/original-name page) " was deleted successfully!")
                                               :success))
                         {:error-handler (fn [{:keys [msg]}]
                                           (notification/show! msg :warning))})
   (state/close-modal!))
 
 (defn delete-page-confirm!
-  [page-name]
-  (when-not (string/blank? page-name)
+  [page]
+  (when page
     (-> (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
-  [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)
-          page (db/entity repo [:block/name page-name])
           page-original-name (:block/original-name page)
           whiteboard? (contains? (set (:block/type page)) "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/get-current-graph-uuid))
           db-based? (config/db-based-graph? repo)]
-      (when (and page (not block?))
+      (when (not block?)
         (->>
          [(when-not config/publishing?
             {:title   (if favorited?
@@ -105,7 +101,7 @@
                         (and db-based?
                              (:logseq.property/built-in? page)))
             {: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?))
                      (state/get-current-page))
@@ -132,7 +128,7 @@
             {:title   (t :export-page)
              :options {:on-click #(shui/dialog-open!
                                    (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"})}})
 
           (when (util/electron?)

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

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

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

@@ -156,12 +156,6 @@
         repo (state/get-current-repo)]
     [:div
      (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"
        (let [items (->> (db-model/get-all-tagged-pages repo)
                         (map second)
@@ -330,7 +324,7 @@
       (str (name f) ": "
            (string/join " | " (rest clause)))
 
-      (contains? #{:page :task :namespace} (keyword f))
+      (contains? #{:page :task} (keyword f))
       (str (name f) ": " (if (vector? (second clause))
                            (second (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"))
       (let [page? (some? (:block/name e))
             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/get-block-referenced-blocks block-id))]
+                         (db/get-block-referenced-blocks (:db/id e)))]
         (when (> (count ref-blocks) 0)
           (let [ref-hiccup (block/->hiccup ref-blocks
                                            {:id (str block-id)
@@ -188,37 +188,34 @@
             (conj result fb))))))))
 
 (rum/defc sub-page-properties-changed < rum/static
-  [page-name v filters-atom]
+  [page-entity v filters-atom]
   (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/local nil ::ref-pages)
   {: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)))
              (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-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)
                 filters-atom (get state ::filters)
                 filter-state (rum/react filters-atom)
-                ref-blocks (db/get-page-referenced-blocks page-name)
                 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))
                 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))
@@ -255,51 +252,50 @@
             (reset! *ref-pages ref-pages)
             (when (or (seq filter-state) (> filter-n 0))
               [: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
                 (references-cp page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
 
 (rum/defc references
-  [page-name]
+  [page-entity]
   (ui/catch-error
    (ui/component-error (if (config/db-based-graph? (state/get-current-repo))
                          "Linked References: Unexpected error."
                          "Linked References: Unexpected error. Please re-index your graph first."))
-   (references* page-name)))
+   (references* page-entity)))
 
 (rum/defcs unlinked-references-aux
   < rum/reactive db-mixins/query
   {:init
    (fn [state]
      (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! *result result))
        (assoc state ::result *result)))}
-  [state page-name _n-ref]
+  [state page _n-ref]
   (let [ref-blocks (rum/react (::result state))]
     (when (seq ref-blocks)
       [:div.references-blocks
        (let [ref-hiccup (block/->hiccup ref-blocks
-                                        {:id (str page-name "-unlinked-")
+                                        {:id (str (:block/original-name page) "-unlinked-")
                                          :ref? true
                                          :group-by-page? true
                                          :editor-box editor/box}
                                         {})]
-         (content/content page-name
+         (content/content (:block/name page)
                           {:hiccup ref-hiccup}))])))
 
 (rum/defcs unlinked-references < rum/reactive
   (rum/local nil ::n-ref)
-  [state page-name]
+  [state page]
   (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")
                :draggable     true
                :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))
                :on-drag-end   (fn [_event]
                                 (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]
             [shadow.loader :as loader]
             [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))
 (rum/defc tldraw-app < rum/reactive
@@ -160,7 +162,7 @@
       (util/stop e)
       (if show-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.flex.w-full.items-center
      [:div.dashboard-card-title-name.font-bold
@@ -248,12 +250,12 @@
     [:div "This feature is not publicly available yet."]))
 
 (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
-
      ;; makes sure the whiteboard will not cover the borders
-     {:key page-name
+     {:key (str page-uuid)
       :ref ref
       :data-breakpoint (name bp)
       :style {:padding "0.5px" :z-index 0
@@ -270,26 +272,27 @@
                            (util/stop e)
                            (common-handler/show-custom-context-menu!
                             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))}
-       (page/page-title page-name {:*hover? (atom false)})]
+       (page/page-title (:block/original-name page) {:*hover? (atom false)})]
 
       [: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"
                          {:hover? true
                           :render-fn (fn [open? refs-count] [:span.whiteboard-page-refs-count-label
                                                              (t :whiteboard/reference-count refs-count)
                                                              (ui/icon (if open? "references-hide" "references-show")
                                                                       {:extension? true})])})]]
-     (tldraw-app page-name block-id)]))
+     (tldraw-app (:block/original-name page) block-id)]))
 
 (rum/defc whiteboard-route <
   (shortcut/mixin :shortcut.handler/whiteboard false)
   [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])]
-    (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
   [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-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-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-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   journal-page? page-alias-set sub-block
   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
   get-current-page set-key-value

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

@@ -3,7 +3,6 @@
   (:require [promesa.core :as p]
             [frontend.state :as state]
             [frontend.config :as config]
-            [frontend.util :as util]
             [frontend.db.utils :as db-utils]
             [frontend.db.async.util :as db-async-util]
             [frontend.db.file-based.async :as file-async]
@@ -16,7 +15,8 @@
             [cljs-time.core :as t]
             [cljs-time.format :as tf]
             [logseq.db :as ldb]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [frontend.util :as util]))
 
 (def <q db-async-util/<q)
 (def <pull db-async-util/<pull)
@@ -70,16 +70,6 @@
         (map :block/original-name properties))
       (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
   [graph property]
   (when-not (config/db-based-graph? graph)
@@ -106,12 +96,13 @@
             (util/uuid-string? name')
             (db/entity [:block/uuid (uuid name')])
             :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)
       e
       (when-let [^Object sqlite @db-browser/*worker]
         (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)
                 conn (db/get-db graph false)
                 block-and-children (cons block children)

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

@@ -33,8 +33,7 @@
    (concat
     [(:block/parent block)
      (:block/left block)
-     (:block/page block)
-     (:block/namespace block)]
+     (:block/page block)]
     (:block/tags block)
     (:block/alias 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.content :as db-content]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
-            [logseq.graph-parser.text :as text]
             [logseq.graph-parser.db :as gp-db]
             [logseq.common.util :as common-util]
             [logseq.common.util.date-time :as date-time-util]
@@ -53,20 +52,6 @@
          [?page :block/name ?page-name]]
        (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?)
 
 (defn get-all-pages
@@ -247,24 +232,25 @@ independent of format as format specific heading characters are stripped"
 (defn get-page-format
   [page-name]
   {: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
-  [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
   ([ids]
@@ -276,19 +262,12 @@ independent of format as format specific heading characters are stripped"
             (map :block/name))))))
 
 (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)
-      (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
   [blocks]
@@ -304,11 +283,6 @@ independent of format as format specific heading characters are stripped"
                 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)
 
 (defn sub-block
@@ -335,6 +309,7 @@ independent of format as format specific heading characters are stripped"
                      f))
                  form))
 
+;; File-based only
 ;; Diverged of get-sorted-page-block-ids
 (defn get-sorted-page-block-ids-and-levels
   "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."
   [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)]
     (loop [result []
            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)))]
           (get-next db parent-id (assoc opts :init? false))))))
 
+(def page? ldb/page?)
+
 (defn get-prev
   "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)."
@@ -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))
                   (db-utils/entity db))))
      (let [parent (:block/parent entity)]
-       (when-not (:block/name parent)
+       (when-not (page? parent)
          parent)))))
 
 (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)]
-     (ldb/get-page-blocks db page opts))))
+     (ldb/get-page-blocks db page-id opts))))
 
 (defn get-page-blocks-count
   [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
                   (parse-uuid page-name))]
     (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
   "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
@@ -569,7 +546,7 @@ independent of format as format specific heading characters are stripped"
   ([page-name alias?]
    (when 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
          alias?
          page-name'
@@ -584,10 +561,11 @@ independent of format as format specific heading characters are stripped"
            (or (when source-page (:block/name source-page))
                page-name')))))))
 
+;; FIXME: should pass page's db id
 (defn get-page-original-name
   [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)
           (:block/name page)))))
 
@@ -603,6 +581,7 @@ independent of format as format specific heading characters are stripped"
          (conn/get-db (state/get-current-repo))
          today)))
 
+;; FIXME: [?page :block/type "journal"]
 (defn get-latest-journals
   ([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
 (defn get-page-referenced-pages
-  [repo page]
+  [repo page-id]
   (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
-                     '[:find [?ref-page-name ...]
+                     '[:find [?ref-page ?ref-page-name]
                        :in $ ?pages
                        :where
                        [(untuple ?pages) [?page ...]]
@@ -643,52 +620,7 @@ independent of format as format specific heading characters are stripped"
                        [?ref-page :block/name ?ref-page-name]]
                      db
                      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
 (defn get-pages-relation
@@ -711,18 +643,16 @@ independent of format as format specific heading characters are stripped"
       (->>
        (d/q q db)
        (map (fn [[page ref-page-name]]
-              [page ref-page-name]))
-       (remove-nested-namespaces-link)))))
+              [page ref-page-name]))))))
 
 ;; get pages who mentioned this page
 ;; TODO: use :block/_refs
 (defn get-pages-that-mentioned-page
-  [repo page include-journals]
+  [repo page-id include-journals]
   (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
-                       :in $ ?pages ?page-name
+                       :in $ ?pages
                        :where
                        [?block :block/refs ?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}
                                         query
-                                        pages
-                                        page)
+                                        pages)
                                react
                                db-utils/seq-flatten)]
       (mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
 
 (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)]
-       (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})]
          (->>
           (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)))))
           db-utils/group-by-page
           (map (fn [[k blocks]]
@@ -769,15 +697,14 @@ independent of format as format specific heading characters are stripped"
                    [k 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 (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
                    [: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)))))
           (util/distinct-by :db/id)))))))
 
+;; TODO: no need to use datalog query, `:block/_refs`
 (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 (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
                                               (: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
                                (sort-by-left-recursive))]
          (db-utils/group-by-page query-result))))))
@@ -822,7 +749,7 @@ independent of format as format specific heading characters are stripped"
 (defn journal-page?
   "sanitized page-name only"
   [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
   "Get blocks which have this property."
@@ -856,6 +783,7 @@ independent of format as format specific heading characters are stripped"
   [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
   [files]
   (let [pages (->> (mapv get-file-page files)
@@ -884,57 +812,10 @@ independent of format as format specific heading characters are stripped"
            page-id)
       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?
   "Given a page name or a page object, check if it is a whiteboard page"
   [page]
-  (ldb/whiteboard-page? (conn/get-db) page))
+  (ldb/whiteboard-page? page))
 
 (defn get-orphaned-pages
   [opts]
@@ -946,18 +827,10 @@ independent of format as format specific heading characters are stripped"
                                       sqlite-create-graph/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?
   [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))))
 
 (defn get-all-whiteboards
@@ -973,14 +846,17 @@ independent of format as format specific heading characters are stripped"
     (conn/get-db repo)))
 
 (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)
-        page (db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])]
+        page (db-utils/entity page-id)]
     (->> (: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)
                     :nonce (:nonce shape)}))))))
 

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

@@ -44,7 +44,6 @@
 ;; sample
 ;; full-text-search ""
 
-;; namespace
 ;; page-property (page)
 ;; page-tags (page)
 ;; all-page-tags
@@ -373,14 +372,6 @@
     {:query (list 'page '?b page-name)
      :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
   [e]
   (let [page-name (-> (page-ref/get-page-name! e)
@@ -445,9 +436,6 @@ Some bindings in this fn:
        (= 'page fe)
        (build-page e)
 
-       (= 'namespace fe)
-       (build-namespace e)
-
        (= 'page-property fe)
        (build-page-property e env)
 

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

@@ -12,7 +12,9 @@
             [clojure.core.async :as async]
             [frontend.db.async.util :as db-async-util]
             [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
 ;; TODO: replace with LRUCache, only keep the latest 20 or 50 items?
@@ -157,13 +159,14 @@
                :page
                (get-in match [:path-params :name])
 
-               :file
-               (get-in match [:path-params :path])
+               :whiteboard
+               (get-in match [:path-params :name])
 
                (date/journal-name))]
     (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!
   [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)
             :current-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})
            with-out-str)]]
 

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

@@ -30,7 +30,8 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.outliner.op :as outliner-op]
             [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-conns worker-state/*sqlite-conns)
@@ -304,7 +305,9 @@
    (when-let [conn (worker-state/get-datascript-conn repo)]
      (let [selector (ldb/read-transit-str selector-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))]
        (ldb/write-transit-str result))))
 
@@ -323,10 +326,11 @@
        (ldb/write-transit-str result))))
 
   (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)]
-     (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
    [_this repo id]
@@ -484,19 +488,21 @@
      (search/page-search repo @conn q limit)))
 
   (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)]
      (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}))))
 
   (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)]
      (let [error-handler (fn [{:keys [msg]}]
                            (worker-util/post-message :notification
                                                      [[: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}))))
 
   (apply-outliner-ops
@@ -537,11 +543,13 @@
 
   ;; Export
   (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
    [this repo]

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

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

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

@@ -93,8 +93,8 @@
         page (db/entity [:block/name page-name])
         journal? (:journal? page)
         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?
                  (rest blocks)
                  blocks)

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

@@ -25,7 +25,8 @@
             [frontend.ui :as ui]
             [frontend.components.whiteboard :as whiteboard]
             [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")))
 
@@ -114,7 +115,9 @@
                         (if (util/uuid-string? 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)]))))
-   :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?
    :isMobile util/mobile?
    :saveAsset save-asset-handler
@@ -133,17 +136,17 @@
                       (state/sidebar-add-block! (state/get-current-repo)
                                                 (:db/id (model/get-page uuid))
                                                 (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))
 

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

@@ -78,6 +78,7 @@
         (p/do!
          (when-not (str/blank? 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?)
                (page-handler/<delete!
                 page-name

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

@@ -102,13 +102,14 @@
 
 (defn- find-block-in-favorites-page
   [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
   [page-block-uuid]
@@ -144,17 +145,20 @@
   "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
    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
 ;; =========
@@ -202,13 +206,12 @@
   (let [db-based?           (config/db-based-graph? repo)
         old-page-name       (common-util/page-name-sanity-lc old-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)
                      (common-util/page-name-sanity-lc old-page-name))]
 
     ;; Redirect to the newly renamed page
     (when redirect?
-      (route-handler/redirect! {:to          (if (model/whiteboard-page? page) :whiteboard :page)
+      (route-handler/redirect! {:to          :page
                                 :push        false
                                 :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
   [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])
         (db-property-util/build-property-hidden-page property))))
 

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

@@ -3473,12 +3473,14 @@
                       (state/get-current-page)
                       (date/today))]
     (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
                    (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)]
       (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
              root-block
@@ -3882,7 +3884,7 @@
 
 (defn block->data-transfer!
   "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")
-            (if (db-model/page? block-or-page-name) "page-name" "block-uuid")
+            (if page? "page-name" "block-uuid")
             (str block-or-page-name)))

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -31,7 +31,6 @@
             [logseq.common.util.page-ref :as page-ref]
             [promesa.core :as p]
             [logseq.common.path :as path]
-            [frontend.handler.property.util :as pu]
             [electron.ipc :as ipc]
             [frontend.context.i18n :refer [t]]
             [frontend.persist-db.browser :as db-browser]
@@ -86,12 +85,14 @@
   (when-let [db (conn/get-db)]
     (let [repo (state/get-current-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))
                               (remove string/blank?)
                               (filter string?)
@@ -125,25 +126,34 @@
         (<favorite-page! page-name)))))
 
 (defn rename!
-  [old-name new-name & {:as _opts}]
+  [page-uuid-or-old-name new-name & {:as _opts}]
   (when-let [^js worker @db-browser/*worker]
     (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))]
       (case (if (string? result') (keyword result') result')
         :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
-        (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))))
 
 (defn <reorder-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]
                     (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
                             :db/id))
@@ -242,14 +252,14 @@
         (common-handler/fix-pages-timestamps))))
 
 (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!
   [page-name filter-state]
@@ -369,14 +379,13 @@
               template (state/get-default-journal-template)
               create-f (fn []
                          (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)
             (if (config/db-based-graph? repo)
               (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-set (set operators))
 (def page-filters ["all page tags"
-                   "namespace"
                    "tags"
                    "property"
                    "sample"])
@@ -155,7 +154,7 @@
               (last f))]
       (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)))
 
     :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"
   ([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}}]
    (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
                                          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
   [name path-params]
@@ -210,4 +204,4 @@
                 :all-journals
                 :home)]
     (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)
         db-id-nonces (or
                       (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)))))
         {: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?)]
@@ -204,16 +204,15 @@
    (p/let [uuid (or (and name (parse-uuid name)) (d/squuid))
            name (or name (str uuid))
            _ (db/transact! (get-default-new-whiteboard-tx name uuid))]
-     name)))
+     uuid)))
 
 (defn <create-new-whiteboard-and-redirect!
   ([]
    (<create-new-whiteboard-and-redirect! (str (d/squuid))))
   ([name]
    (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
   [block-id point]

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

@@ -13,7 +13,10 @@
             [frontend.components.bug-report :as bug-report]
             [frontend.components.user.login :as login]
             [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
 (def routes
@@ -25,10 +28,6 @@
     {:name :repos
      :view repo/repos}]
 
-   ["/whiteboard/:name"
-    {:name :whiteboard
-     :view whiteboard/whiteboard-route}]
-
    ["/whiteboards"
     {:name :whiteboards
      :view whiteboard/whiteboard-dashboard}]
@@ -37,17 +36,16 @@
     {:name :repo-add
      :view setups/picker}]
 
-   ["/all-files"
-    {:name :all-files
-     :view file/files}]
-
-   ["/file/:path"
-    {:name :file
-     :view file/file}]
-
    ["/page/:name"
     {: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"
     {:name :page-block
@@ -93,7 +91,15 @@
     {:name :user-login
      :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
   "Get matched result from search first, and then filter by worker db"
-  [page]
+  [page-id]
   (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
-                                        (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)
             result (block-search repo q {:limit 100})
             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}]
   (let [db @conn
         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))
       (let [transact-opts (if replace-tx? {:replace? true} {})
             *fix-tx-data (atom [])]

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

@@ -4,18 +4,16 @@
             [logseq.outliner.tree :as otree]
             [frontend.worker.file.core :as worker-file]
             [datascript.core :as d]
-            [logseq.common.util :as common-util]
             [logseq.graph-parser.property :as gp-property]))
 
 (defn block->content
   "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)
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
     (worker-file/tree->file-content repo db tree
@@ -54,7 +52,7 @@
                                        (safe-keywordize b'))) blocks))
                     children (if whiteboard?
                                blocks'
-                               (otree/blocks->vec-tree repo db blocks' name))
+                               (otree/blocks->vec-tree repo db blocks' (:db/id page)))
                     page' (safe-keywordize page)]
                 (assoc page' :block/children children))))))
 
@@ -64,4 +62,4 @@
        (map (fn [d]
               (let [e (d/entity db (:e d))]
                 [(: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?))
             (dissoc-request! request-id)
             (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
                 (file/save-tree! repo conn page-block tree-or-blocks blocks-just-deleted? context request-id)
                 (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)))
           date-formatter (:date-formatter context)
           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)
           journal-page? (worker-date/valid-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.string :as string]
             [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
   "Unsanitized names"
@@ -105,10 +106,10 @@
 
 (defn replace-page-ref
   "Unsanitized only"
-  [db config old-original-name new-name]
+  [db config page new-name]
   ;; 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)))
         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)]

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

@@ -7,7 +7,6 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [datascript.core :as d]
             [clojure.string :as string]
-            [frontend.worker.date :as date]
             [logseq.graph-parser.text :as text]
             [logseq.common.util :as common-util]
             [logseq.common.config :as common-config]
@@ -78,42 +77,23 @@
              persist-op?         true}
       :as options}]
   (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)
         with-uuid? (if (uuid? uuid) uuid true)
         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))
                        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)
                                            (assoc :block/format format)))
                                      pages)
                        txs      (->> pages
-                           ;; for namespace pages, only last page need properties
-                                     drop-last
                                      (mapcat #(build-page-tx repo conn config date-formatter format 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 (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
                                              create-first-block?
                                              (not (or whiteboard? class?))
-                                             (ldb/page-empty? @conn (:db/id (d/entity @conn [:block/name page-name])))
                                              page-txs)
                                         (let [page-id [:block/uuid (:block/uuid (first page-txs))]]
                                           [(sqlite-util/block-with-timestamps
@@ -201,12 +181,12 @@
 (defn delete!
   "Deletes a page. Returns true if able to delete page. If unable to delete,
   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
                                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)
           truncate-blocks-tx-data (mapv
                                    (fn [block]
@@ -229,19 +209,12 @@
                                  [[:db.fn/retractEntity [:file/path file-path]]])
               ;; if other page alias this pagename,
               ;; 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)]
 
             (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
   "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]
             [clojure.string :as string]
-            [logseq.common.util.page-ref :as page-ref]
             [frontend.worker.file.util :as wfu]
             [frontend.worker.file.page-rename :as page-rename]
             [logseq.db.sqlite.util :as sqlite-util]
             [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
   "Replace from-page refs with to-page"
@@ -92,47 +64,48 @@
 
 (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
   "Construct the full path given old full path and the file sanitized body.
@@ -145,9 +118,8 @@
     (common-util/string-join-path parts)))
 
 (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)))
       (let [old-path (:file/path file)
             new-file-name (wfu/file-name-sanity new-page-name) ;; w/o file extension
@@ -159,27 +131,24 @@
 
 (defn- rename-page-aux
   "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
-        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)
-        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)
-      (let [old-original-name   (:block/original-name page)
-            page-txs            (when-not merge?
+      (let [page-txs            (when-not merge?
                                   [{:db/id               (:db/id page)
-                                    :block/uuid          (:block/uuid page)
                                     :block/name          new-page-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
                         other-tx
                         (when-not db-based?
                           (->>
                            (concat
                             ;;  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
                             tx-data)
 
@@ -187,101 +156,44 @@
 
         (ldb/transact! conn txs {:outliner-op :rename-page
                                  :data (cond->
-                                        {:old-name old-name
+                                        {:old-name old-page-name
                                          :new-name new-name}
                                          (and old-path new-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)"
-  [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!
-  [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
-        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)
         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-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)]
     (cond
-      (ldb/built-in? page-e)
-      :built-in-page
-
       (string/blank? new-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
   [repo conn from-page-name to-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)
       (outliner-tx/transact!
        {:persist-op? true
@@ -512,7 +512,7 @@
   (let [config (worker-state/get-config repo)]
     (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]))
-            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
                          :uuid self :persist-op? false}]
         (cond
@@ -521,7 +521,7 @@
           (and exist-page
                (not= (:block/uuid exist-page) self)
                (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))
 
           ;; same name but different uuid
@@ -531,14 +531,14 @@
           (and exist-page
                (not= (:block/uuid exist-page) self))
           (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)
             (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,
           ;; then we need to rename the client-page to remote-page-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
           ;; just create-page
@@ -550,8 +550,7 @@
 (defn apply-remote-remove-page-ops
   [repo conn 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
   "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.worker.util :as worker-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
 (defonce indices (atom nil))
@@ -225,18 +226,8 @@
 
 (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 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
   "Convert a block to the index for searching"
@@ -246,7 +237,7 @@
         block? (nil? name)
         db-based? (sqlite-util/db-based-graph? repo)]
     (when-not (or
-               (and page? name (whiteboard-page? db name))
+               (and page? name (whiteboard-page? db uuid))
                (and block? (> (count content) 10000))
                (and (empty? properties)
                     (or (and block? (string/blank? content))

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

@@ -49,7 +49,8 @@
             [frontend.modules.layout.core]
             [frontend.handler.code :as code-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
 
@@ -61,6 +62,7 @@
                 (and (vector? id-or-name) (= (count id-or-name) 2)) 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)]
+                ;; 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)])]
       (db-async/<pull (state/get-current-repo) eid))))
 
@@ -642,7 +644,8 @@
                                          [nil (uuid block-uuid-or-page-name)]
                                          [block-uuid-or-page-name nil])
                 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}))
                 custom-uuid            (or customUUID (:id properties))
                 custom-uuid            (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
@@ -816,8 +819,9 @@
 (def ^:export get_current_page_blocks_tree
   (fn []
     (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
             blocks (sdk-utils/normalize-keyword-for-json blocks)]
         (bean/->js blocks)))))
@@ -825,9 +829,9 @@
 (def ^:export get_page_blocks_tree
   (fn [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)]
           (bean/->js blocks))))))
 
@@ -837,24 +841,22 @@
           block (db-async/<get-block repo page-name-or-uuid :children? false)
           ;; load refs to db
           _ (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))]
     (bean/->js (sdk-utils/normalize-keyword-for-json ref-blocks))))
 
 (defn ^:export get_pages_from_namespace
   [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
   [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
   [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))
              [(:db/id (db/entity [:block/uuid fbid]))]))
 
-      (testing "namespace classes"
+      (testing "classes parent"
         (page-handler/create! "class2" opts)
       ;; set class2's parent to class1
         (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!
                      :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
   (load-test-files [{:file/path "aa.md"
                      :file/content "alias:: ab, ac"}
@@ -99,31 +73,6 @@
          (map first (model/get-pages-that-mentioned-page test-helper/test-db "generic page" false)))
       "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
   (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)")))
       "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
   (testing "nil or blank strings should be ignored"
     (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]]
             [frontend.test.helper :as test-helper]
             [datascript.core :as d]
-            [frontend.handler.page :as page-handler]
             [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
 
@@ -43,66 +40,43 @@
         (is (= "New name" (:block/original-name 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])]
         opts))
       (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)
         (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"
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
                           :affected-blocks