Explorar o código

Remove more :block/name lookup ref usage

Tienson Qin hai 1 ano
pai
achega
9df8918f94
Modificáronse 47 ficheiros con 262 adicións e 288 borrados
  1. 12 15
      deps/db/src/logseq/db.cljs
  2. 1 1
      deps/db/src/logseq/db/sqlite/common_db.cljs
  3. 3 2
      deps/graph-parser/src/logseq/graph_parser/block.cljs
  4. 2 3
      deps/graph-parser/src/logseq/graph_parser/db.cljs
  5. 5 5
      deps/graph-parser/src/logseq/graph_parser/exporter.cljs
  6. 1 0
      deps/graph-parser/src/logseq/graph_parser/extract.cljc
  7. 4 3
      deps/graph-parser/test/logseq/graph_parser_test.cljs
  8. 3 3
      src/main/frontend/components/block.cljs
  9. 8 29
      src/main/frontend/components/cmdk.cljs
  10. 1 1
      src/main/frontend/components/file.cljs
  11. 1 1
      src/main/frontend/components/page_menu.cljs
  12. 2 2
      src/main/frontend/components/property/value.cljs
  13. 1 1
      src/main/frontend/components/query_table.cljs
  14. 11 11
      src/main/frontend/components/reference.cljs
  15. 4 3
      src/main/frontend/components/right_sidebar.cljs
  16. 2 5
      src/main/frontend/db/model.cljs
  17. 1 1
      src/main/frontend/db_worker.cljs
  18. 4 4
      src/main/frontend/extensions/slide.cljs
  19. 2 2
      src/main/frontend/extensions/srs.cljs
  20. 1 1
      src/main/frontend/extensions/tldraw.cljs
  21. 2 2
      src/main/frontend/handler/block.cljs
  22. 6 8
      src/main/frontend/handler/common/page.cljs
  23. 4 4
      src/main/frontend/handler/db_based/property.cljs
  24. 2 2
      src/main/frontend/handler/editor.cljs
  25. 4 4
      src/main/frontend/handler/events.cljs
  26. 3 2
      src/main/frontend/handler/export/opml.cljs
  27. 35 36
      src/main/frontend/handler/file_based/page_property.cljs
  28. 1 1
      src/main/frontend/handler/file_based/repo.cljs
  29. 16 16
      src/main/frontend/handler/import.cljs
  30. 18 22
      src/main/frontend/handler/page.cljs
  31. 7 9
      src/main/frontend/handler/property.cljs
  32. 4 4
      src/main/frontend/handler/route.cljs
  33. 1 1
      src/main/frontend/handler/search.cljs
  34. 5 5
      src/main/frontend/handler/whiteboard.cljs
  35. 4 3
      src/main/frontend/template.cljs
  36. 4 5
      src/main/frontend/util/page.cljs
  37. 2 2
      src/main/frontend/worker/export.cljs
  38. 1 1
      src/main/frontend/worker/file.cljs
  39. 2 2
      src/main/frontend/worker/rtc/core.cljs
  40. 24 24
      src/test/frontend/db/db_based_model_test.cljs
  41. 5 5
      src/test/frontend/handler/db_based/property_test.cljs
  42. 7 3
      src/test/frontend/handler/editor_test.cljs
  43. 10 10
      src/test/frontend/worker/handler/page/rename_test.cljs
  44. 1 1
      src/test/frontend/worker/pipeline_test.cljs
  45. 1 1
      src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs
  46. 3 2
      src/test/frontend/worker/rtc/rtc_effects_test.cljs
  47. 21 20
      src/test/frontend/worker/rtc/rtc_fns_test.cljs

+ 12 - 15
deps/db/src/logseq/db.cljs

@@ -114,7 +114,7 @@
 
 
 (defn get-page-blocks
 (defn get-page-blocks
   "Return blocks of the designated page, without using cache.
   "Return blocks of the designated page, without using cache.
-   page - name / title of the page"
+   page-id - eid"
   [db page-id {:keys [pull-keys]
   [db page-id {:keys [pull-keys]
             :or {pull-keys '[*]}}]
             :or {pull-keys '[*]}}]
   (when page-id
   (when page-id
@@ -164,18 +164,20 @@
        (map first)
        (map first)
        (remove hidden-page?)))
        (remove hidden-page?)))
 
 
+(def get-first-page-by-name sqlite-common-db/get-first-page-by-name)
+
 (defn page-exists?
 (defn page-exists?
   "Whether a page exists."
   "Whether a page exists."
   [db page-name]
   [db page-name]
   (when page-name
   (when page-name
-    (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)])))
+    (some? (get-first-page-by-name db page-name))))
 
 
 (defn page-empty?
 (defn page-empty?
   "Whether a page is empty. Does it has a non-page block?
   "Whether a page is empty. Does it has a non-page block?
   `page-id` could be either a string or a db/id."
   `page-id` could be either a string or a db/id."
   [db page-id]
   [db page-id]
   (let [page-id (if (string? page-id)
   (let [page-id (if (string? page-id)
-                  [:block/name (common-util/page-name-sanity-lc page-id)]
+                  (get-first-page-by-name db page-id)
                   page-id)
                   page-id)
         page (d/entity db page-id)]
         page (d/entity db page-id)]
     (nil? (:block/_left page))))
     (nil? (:block/_left page))))
@@ -190,8 +192,8 @@
         orphaned-pages (->>
         orphaned-pages (->>
                         (map
                         (map
                          (fn [page]
                          (fn [page]
-                           (let [name (common-util/page-name-sanity-lc page)]
-                             (when-let [page (d/entity db [:block/name name])]
+                           (when-let [page (d/entity db (get-first-page-by-name db page))]
+                             (let [name (:block/name page)]
                                (and
                                (and
                                 (empty-ref-f page)
                                 (empty-ref-f page)
                                 (or
                                 (or
@@ -397,14 +399,11 @@
 
 
 (defn get-page
 (defn get-page
   "Get a page given its unsanitized name"
   "Get a page given its unsanitized name"
-  [db page-name]
-  (d/entity db [:block/name (common-util/page-name-sanity-lc (name page-name))]))
-
-(defn get-page-uuid
-  "Get a user page's uuid given its unsanitized name"
-  ;; Get a page's uuid given its unsanitized name
-  [db page-name]
-  (:block/uuid (get-page db page-name)))
+  [db page-name-or-uuid]
+  (if-let [id (if (uuid? page-name-or-uuid) page-name-or-uuid
+                  (parse-uuid page-name-or-uuid))]
+    (d/entity db [:block/uuid id])
+    (d/entity db (get-first-page-by-name db (name page-name-or-uuid)))))
 
 
 (defn get-page-alias
 (defn get-page-alias
   [db page-id]
   [db page-id]
@@ -501,8 +500,6 @@
   [db]
   [db]
   (when db (:graph/uuid (d/entity db :logseq.kv/graph-uuid))))
   (when db (:graph/uuid (d/entity db :logseq.kv/graph-uuid))))
 
 
-(def get-first-page-by-name sqlite-common-db/get-first-page-by-name)
-
 (defn page?
 (defn page?
   [block]
   [block]
   (and block
   (and block

+ 1 - 1
deps/db/src/logseq/db/sqlite/common_db.cljs

@@ -13,7 +13,7 @@
   (d/datoms db :avet :block/name (common-util/page-name-sanity-lc page-name)))
   (d/datoms db :avet :block/name (common-util/page-name-sanity-lc page-name)))
 
 
 (defn get-first-page-by-name
 (defn get-first-page-by-name
-  "Return the oldest page"
+  "Return the oldest page's db id"
   [db page-name]
   [db page-name]
   (first (sort (map :e (get-pages-by-name db page-name)))))
   (first (sort (map :e (get-pages-by-name db page-name)))))
 
 

+ 3 - 2
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -13,7 +13,8 @@
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
             [logseq.common.util.block-ref :as block-ref]
             [logseq.common.util.block-ref :as block-ref]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.page-ref :as page-ref]
-            [datascript.impl.entity :as de]))
+            [datascript.impl.entity :as de]
+            [logseq.db :as ldb]))
 
 
 (defn heading-block?
 (defn heading-block?
   [block]
   [block]
@@ -292,7 +293,7 @@
     (and original-page-name (string? original-page-name))
     (and original-page-name (string? original-page-name))
     (let [original-page-name (common-util/remove-boundary-slashes original-page-name)
     (let [original-page-name (common-util/remove-boundary-slashes original-page-name)
           [original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)
           [original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)
-          page-entity (some-> db (d/entity [:block/name page-name]))
+          page-entity (some-> db (ldb/get-page page-name))
           original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
           original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
       (merge
       (merge
        {:block/name page-name
        {:block/name page-name

+ 2 - 3
deps/graph-parser/src/logseq/graph_parser/db.cljs

@@ -43,7 +43,7 @@
   "Creates default pages if one of the default pages does not exist. This
   "Creates default pages if one of the default pages does not exist. This
    fn is idempotent"
    fn is idempotent"
   [db-conn]
   [db-conn]
-  (when-not (d/entity @db-conn [:block/name "card"])
+  (when-not (ldb/get-page @db-conn "card")
     (let [built-in-pages (build-pages-tx built-in-pages)]
     (let [built-in-pages (build-pages-tx built-in-pages)]
       (ldb/transact! db-conn built-in-pages))))
       (ldb/transact! db-conn built-in-pages))))
 
 
@@ -56,6 +56,5 @@
 
 
 (defn get-page-file
 (defn get-page-file
   [db page-name]
   [db page-name]
-  (some-> (or (d/entity db [:block/name page-name])
-              (d/entity db [:block/original-name page-name]))
+  (some-> (ldb/get-page db page-name)
           :block/file))
           :block/file))

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

@@ -24,7 +24,7 @@
 (defn- get-pid
 (defn- get-pid
   "Get a property's id (name or uuid) given its name. For db graphs"
   "Get a property's id (name or uuid) given its name. For db graphs"
   [db property-name]
   [db property-name]
-  (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc (name property-name))])))
+  (:block/uuid (ldb/get-page db property-name)))
 
 
 (defn- add-missing-timestamps
 (defn- add-missing-timestamps
   "Add updated-at or created-at timestamps if they doesn't exist"
   "Add updated-at or created-at timestamps if they doesn't exist"
@@ -587,7 +587,7 @@
                                      (not (:block/file %))))
                                      (not (:block/file %))))
                        ;; remove file path relative
                        ;; remove file path relative
                        (map #(dissoc % :block/file)))
                        (map #(dissoc % :block/file)))
-        existing-pages (keep #(d/entity @conn [:block/name (:block/name %)]) all-pages)
+        existing-pages (keep #(ldb/get-page @conn (:block/name %)) all-pages)
         existing-page-names (set (map :block/name existing-pages))
         existing-page-names (set (map :block/name existing-pages))
         new-pages (remove #(contains? existing-page-names (:block/name %)) all-pages)
         new-pages (remove #(contains? existing-page-names (:block/name %)) all-pages)
         page-names-to-uuids (into {}
         page-names-to-uuids (into {}
@@ -865,7 +865,7 @@
                     [(get ?bp ?prop-uuid) ?_v]]
                     [(get ?bp ?prop-uuid) ?_v]]
                   @conn
                   @conn
                   (set (map :block/name user-classes)))
                   (set (map :block/name user-classes)))
-             (remove #(ldb/built-in? (d/entity @conn [:block/name (second %)])))
+             (remove #(ldb/built-in? (ldb/get-page @conn (second %))))
              (reduce (fn [acc [class-id _prop-name prop-uuid]]
              (reduce (fn [acc [class-id _prop-name prop-uuid]]
                        (update acc class-id (fnil conj #{}) prop-uuid))
                        (update acc class-id (fnil conj #{}) prop-uuid))
                      {}))
                      {}))
@@ -924,10 +924,10 @@
      (ldb/create-favorites-page repo)
      (ldb/create-favorites-page repo)
      (if-let [favorited-ids
      (if-let [favorited-ids
               (keep (fn [page-name]
               (keep (fn [page-name]
-                      (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
+                      (some-> (ldb/get-page @conn page-name)
                               :block/uuid))
                               :block/uuid))
                     favorites)]
                     favorites)]
-       (let [page-entity (d/entity @conn [:block/name common-config/favorites-page-name])]
+       (let [page-entity (ldb/get-page @conn common-config/favorites-page-name)]
          (insert-favorites repo favorited-ids (:db/id page-entity)))
          (insert-favorites repo favorited-ids (:db/id page-entity)))
        (log-fn :no-favorites-found {:favorites favorites})))))
        (log-fn :no-favorites-found {:favorites favorites})))))
 
 

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

@@ -225,6 +225,7 @@
           blocks (->> (gp-block/extract-blocks ast content false format options')
           blocks (->> (gp-block/extract-blocks ast content false format options')
                       (attach-block-ids-if-match override-uuids)
                       (attach-block-ids-if-match override-uuids)
                       (mapv #(gp-block/fix-block-id-if-duplicated! db page-name extracted-block-ids %))
                       (mapv #(gp-block/fix-block-id-if-duplicated! db page-name extracted-block-ids %))
+                      ;; FIXME: use page uuid
                       (gp-block/with-parent-and-left {:block/name page-name})
                       (gp-block/with-parent-and-left {:block/name page-name})
                       (vec))
                       (vec))
           ref-pages (atom #{})
           ref-pages (atom #{})

+ 4 - 3
deps/graph-parser/test/logseq/graph_parser_test.cljs

@@ -5,7 +5,8 @@
             [logseq.graph-parser.db :as gp-db]
             [logseq.graph-parser.db :as gp-db]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.property :as gp-property]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [logseq.db :as ldb]))
 
 
 (def foo-edn
 (def foo-edn
   "Example exported whiteboard page as an edn exportable."
   "Example exported whiteboard page as an edn exportable."
@@ -414,7 +415,7 @@ id:: 63f199bc-c737-459f-983d-84acfcda14fe
 id:: 63f199bc-c737-459f-983d-84acfcda14fe
 id:: 63f199bc-c737-459f-983d-84acfcda14fe
 "
 "
                                parse-opts)
                                parse-opts)
-      (let [blocks (:block/_parent (d/entity @conn [:block/name "foo"]))]
+      (let [blocks (:block/_parent (ldb/get-page @conn "foo"))]
         (is (= 2 (count blocks)))
         (is (= 2 (count blocks)))
         (is (= 1 (count (filter #(= (:block/uuid %) block-id) blocks)))))))
         (is (= 1 (count (filter #(= (:block/uuid %) block-id) blocks)))))))
 
 
@@ -442,6 +443,6 @@ bar
              (-> (d/entity @conn [:block/uuid block-id])
              (-> (d/entity @conn [:block/uuid block-id])
                  :block/page
                  :block/page
                  :block/name)))
                  :block/name)))
-      (let [bar-block (first (:block/_parent (d/entity @conn [:block/name "bar"])))]
+      (let [bar-block (first (:block/_parent (ldb/get-page @conn "bar")))]
         (is (some? (:block/uuid bar-block)))
         (is (some? (:block/uuid bar-block)))
         (is (not= (:block/uuid bar-block) block-id))))))
         (is (not= (:block/uuid bar-block) block-id))))))

+ 3 - 3
src/main/frontend/components/block.cljs

@@ -711,7 +711,7 @@
   (when-let [page-name-in-block (:block/name page)]
   (when-let [page-name-in-block (:block/name page)]
     (let [page-name-in-block (common-util/remove-boundary-slashes page-name-in-block)
     (let [page-name-in-block (common-util/remove-boundary-slashes page-name-in-block)
           page-name (util/page-name-sanity-lc page-name-in-block)
           page-name (util/page-name-sanity-lc page-name-in-block)
-          page-entity (db/entity [:block/name page-name])
+          page-entity (db/get-page page-name)
           whiteboard-page? (model/whiteboard-page? page-name)
           whiteboard-page? (model/whiteboard-page? page-name)
           inner (page-inner config
           inner (page-inner config
                             page-name-in-block
                             page-name-in-block
@@ -719,7 +719,7 @@
                             page-entity contents-page? children html-export? label whiteboard-page?)
                             page-entity contents-page? children html-export? label whiteboard-page?)
           modal? (:modal/show? @state/state)]
           modal? (:modal/show? @state/state)]
       (if (and (not (util/mobile?))
       (if (and (not (util/mobile?))
-               (not= (util/page-name-sanity-lc page-name-in-block) (:id config))
+               (not= page-name (:id config))
                (not (false? preview?))
                (not (false? preview?))
                (not disable-preview?)
                (not disable-preview?)
                (not modal?))
                (not modal?))
@@ -885,7 +885,7 @@
 (defn- get-page
 (defn- get-page
   [label]
   [label]
   (when-let [label-text (get-label-text label)]
   (when-let [label-text (get-label-text label)]
-    (db/entity [:block/name (util/page-name-sanity-lc label-text)])))
+    (db/get-page label-text)))
 
 
 (defn- macro->text
 (defn- macro->text
   [name arguments]
   [name arguments]

+ 8 - 29
src/main/frontend/components/cmdk.cljs

@@ -106,7 +106,7 @@
                             :else
                             :else
                             (take 5 items))))
                             (take 5 items))))
         page-exists? (when-not (string/blank? input)
         page-exists? (when-not (string/blank? input)
-                       (db/entity [:block/name (string/trim input)]))
+                       (db/get-page (string/trim input)))
         include-slash? (or (string/includes? input "/")
         include-slash? (or (string/includes? input "/")
                            (string/starts-with? input "/"))
                            (string/starts-with? input "/"))
         order* (cond
         order* (cond
@@ -216,15 +216,15 @@
                        (remove nil?)
                        (remove nil?)
                        (map
                        (map
                         (fn [page]
                         (fn [page]
-                          (let [entity (db/entity [:block/name (util/page-name-sanity-lc page)])
+                          (let [entity (db/get-page page)
                                 whiteboard? (= (:block/type entity) "whiteboard")
                                 whiteboard? (= (:block/type entity) "whiteboard")
                                 source-page (model/get-alias-source-page repo page)]
                                 source-page (model/get-alias-source-page repo page)]
                             (hash-map :icon (if whiteboard? "whiteboard" "page")
                             (hash-map :icon (if whiteboard? "whiteboard" "page")
                                       :icon-theme :gray
                                       :icon-theme :gray
                                       :text page
                                       :text page
                                       :source-page (if source-page
                                       :source-page (if source-page
-                                              (:block/original-name source-page)
-                                              page))))))]
+                                                     (:block/original-name source-page)
+                                                     page))))))]
       (swap! !results update group        merge {:status :success :items items}))))
       (swap! !results update group        merge {:status :success :items items}))))
 
 
 (defmethod load-results :whiteboards [group state]
 (defmethod load-results :whiteboards [group state]
@@ -238,7 +238,7 @@
                        (remove nil?)
                        (remove nil?)
                        (keep
                        (keep
                         (fn [page]
                         (fn [page]
-                          (let [entity (db/entity [:block/name (util/page-name-sanity-lc page)])
+                          (let [entity (db/get-page page)
                                 whiteboard? (= (:block/type entity) "whiteboard")]
                                 whiteboard? (= (:block/type entity) "whiteboard")]
                             (when whiteboard?
                             (when whiteboard?
                               (hash-map :icon "whiteboard"
                               (hash-map :icon "whiteboard"
@@ -314,27 +314,6 @@
                    files)]
                    files)]
       (swap! !results update group        merge {:status :success :items items}))))
       (swap! !results update group        merge {:status :success :items items}))))
 
 
-;; FIXME: recent search
-;; (defmethod load-results :recents [group state]
-;;   (let [!input (::input state)
-;;         !results (::results state)
-;;         recent-searches (mapv (fn [q] {:type :search :data q}) (db/get-key-value :recent/search))
-;;         recent-pages (->> (filter string? (db/get-key-value :recent/pages))
-;;                           (keep (fn [page]
-;;                                   (when-let [page-entity (db/entity [:block/name (util/page-name-sanity-lc page)])]
-;;                                     {:type :page :data (:block/original-name page-entity)})))
-;;                           vec)]
-;;     (swap! !results assoc-in [group :status] :loading)
-;;     (let [items (->> (concat recent-searches recent-pages)
-;;                      (filter #(string/includes? (lower-case-str (:data %)) (lower-case-str @!input)))
-;;                      (map #(hash-map :icon (if (= :page (:type %)) "page" "history")
-;;                                      :icon-theme :gray
-;;                                      :text (:data %)
-;;                                      :source-recent %
-;;                                      :source-page (when (= :page (:type %)) (:data %))
-;;                                      :source-search (when (= :search (:type %)) (:data %)))))]
-;;       (swap! !results update group merge {:status :success :items items}))))
-
 (defn- get-filter-q
 (defn- get-filter-q
   [input]
   [input]
   (or (when (string/starts-with? input "/")
   (or (when (string/starts-with? input "/")
@@ -407,7 +386,7 @@
 (defmethod handle-action :open-page [_ state _event]
 (defmethod handle-action :open-page [_ state _event]
   (when-let [page-name (get-highlighted-page-name state)]
   (when-let [page-name (get-highlighted-page-name state)]
     (let [redirect-page-name (model/get-redirect-page-name page-name)
     (let [redirect-page-name (model/get-redirect-page-name page-name)
-          page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])
+          page (db/get-page redirect-page-name)
           original-name (:block/original-name page)]
           original-name (:block/original-name page)]
       (if (= (:block/type page) "whiteboard")
       (if (= (:block/type page) "whiteboard")
         (route-handler/redirect-to-page! original-name)
         (route-handler/redirect-to-page! original-name)
@@ -435,7 +414,7 @@
 (defmethod handle-action :open-page-right [_ state _event]
 (defmethod handle-action :open-page-right [_ state _event]
   (when-let [page-name (get-highlighted-page-name state)]
   (when-let [page-name (get-highlighted-page-name state)]
     (let [redirect-page-name (model/get-redirect-page-name page-name)
     (let [redirect-page-name (model/get-redirect-page-name page-name)
-          page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])]
+          page (db/get-page redirect-page-name)]
       (when page
       (when page
         (editor-handler/open-block-in-sidebar! (:block/uuid page))))
         (editor-handler/open-block-in-sidebar! (:block/uuid page))))
     (state/close-modal!)))
     (state/close-modal!)))
@@ -509,7 +488,7 @@
        create-whiteboard? (whiteboard-handler/<create-new-whiteboard-and-redirect! @!input)
        create-whiteboard? (whiteboard-handler/<create-new-whiteboard-and-redirect! @!input)
        create-page? (page-handler/<create! @!input {:redirect? true}))
        create-page? (page-handler/<create! @!input {:redirect? true}))
      (if create-class?
      (if create-class?
-       (state/pub-event! [:class/configure (db/entity [:block/name (util/page-name-sanity-lc class)])])
+       (state/pub-event! [:class/configure (db/get-page class)])
        (state/close-modal!)))))
        (state/close-modal!)))))
 
 
 (defn- get-filter-user-input
 (defn- get-filter-user-input

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

@@ -127,7 +127,7 @@
                                 :href (rfe/href :page {:name original-name})
                                 :href (rfe/href :page {:name original-name})
                                 :on-click (fn [e]
                                 :on-click (fn [e]
                                             (when (gobj/get e "shiftKey")
                                             (when (gobj/get e "shiftKey")
-                                              (when-let [page (db/entity [:block/name (util/page-name-sanity-lc original-name)])]
+                                              (when-let [page (db/get-page original-name)]
                                                 (state/sidebar-add-block!
                                                 (state/sidebar-add-block!
                                                  (state/get-current-repo)
                                                  (state/get-current-repo)
                                                  (:db/id page)
                                                  (:db/id page)

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

@@ -136,7 +136,7 @@
              :options {:on-click
              :options {:on-click
                        (fn []
                        (fn []
                          (page-handler/update-public-attribute!
                          (page-handler/update-public-attribute!
-                          page-name
+                          page
                           (if public? false true))
                           (if public? false true))
                          (state/close-modal!))}})
                          (state/close-modal!))}})
 
 

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

@@ -103,11 +103,11 @@
                          (let [journal (date/js-date->journal-title gd)]
                          (let [journal (date/js-date->journal-title gd)]
                            (p/do!
                            (p/do!
                             (shui/popup-hide! id)
                             (shui/popup-hide! id)
-                            (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
+                            (when-not (db/get-page journal)
                               (page-handler/<create! journal {:redirect? false
                               (page-handler/<create! journal {:redirect? false
                                                               :create-first-block? false}))
                                                               :create-first-block? false}))
                             (when (fn? on-change)
                             (when (fn? on-change)
-                              (on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
+                              (on-change (db/get-page journal)))
                             (exit-edit-property))))))]
                             (exit-edit-property))))))]
                (shui/calendar
                (shui/calendar
                 (cond->
                 (cond->

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

@@ -205,7 +205,7 @@
     (boolean? value) (str value)
     (boolean? value) (str value)
     ;; string values will attempt to be rendered as pages, falling back to
     ;; string values will attempt to be rendered as pages, falling back to
     ;; inline-text when no page entity is found
     ;; inline-text when no page entity is found
-    (string? value) (if-let [page (db/entity [:block/name (util/page-name-sanity-lc value)])]
+    (string? value) (if-let [page (db/get-page value)]
                       (page-cp {} page)
                       (page-cp {} page)
                       (inline-text row-block row-format value))
                       (inline-text row-block row-format value))
     ;; render uuids as page refs
     ;; render uuids as page refs

+ 11 - 11
src/main/frontend/components/reference.cljs

@@ -25,7 +25,7 @@
   (sort-by second #(> %1 %2) references))
   (sort-by second #(> %1 %2) references))
 
 
 (defn filtered-refs
 (defn filtered-refs
-  [page-name filters filters-atom filtered-references]
+  [page filters filters-atom filtered-references]
   [:div.flex.gap-2.flex-wrap.items-center
   [:div.flex.gap-2.flex-wrap.items-center
    (for [[ref-name ref-count] filtered-references]
    (for [[ref-name ref-count] filtered-references]
      (when ref-name
      (when ref-name
@@ -38,13 +38,13 @@
                        (swap! filters-atom #(if (nil? (get filters lc-reference))
                        (swap! filters-atom #(if (nil? (get filters lc-reference))
                                               (assoc % lc-reference (not (.-shiftKey e)))
                                               (assoc % lc-reference (not (.-shiftKey e)))
                                               (dissoc % lc-reference)))
                                               (dissoc % lc-reference)))
-                       (page-handler/save-filter! page-name @filters-atom))
+                       (page-handler/save-filter! page @filters-atom))
            :small? true
            :small? true
            :variant :outline
            :variant :outline
            :key ref-name))))])
            :key ref-name))))])
 
 
 (rum/defcs filter-dialog-inner < rum/reactive (rum/local "" ::filterSearch)
 (rum/defcs filter-dialog-inner < rum/reactive (rum/local "" ::filterSearch)
-  [state filters-atom *references page-name]
+  [state page-entity filters-atom *references]
   (let [filter-search (get state ::filterSearch)
   (let [filter-search (get state ::filterSearch)
         references (rum/react *references)
         references (rum/react *references)
         filtered-references  (frequencies-sort
         filtered-references  (frequencies-sort
@@ -73,11 +73,11 @@
         (when (seq includes)
         (when (seq includes)
           [:div.flex.flex-row.flex-wrap.center-items
           [:div.flex.flex-row.flex-wrap.center-items
            [:div.mr-1.font-medium.py-1 (t :linked-references/filter-includes)]
            [:div.mr-1.font-medium.py-1 (t :linked-references/filter-includes)]
-           (filtered-refs page-name filters filters-atom includes)])
+           (filtered-refs page-entity filters filters-atom includes)])
         (when (seq excludes)
         (when (seq excludes)
           [:div.flex.flex-row.flex-wrap
           [:div.flex.flex-row.flex-wrap
            [:div.mr-1.font-medium.py-1 (t :linked-references/filter-excludes)]
            [:div.mr-1.font-medium.py-1 (t :linked-references/filter-excludes)]
-           (filtered-refs page-name filters filters-atom excludes)])])
+           (filtered-refs page-entity filters filters-atom excludes)])])
      [:div.cp__filters-input-panel.flex
      [:div.cp__filters-input-panel.flex
       (ui/icon "search")
       (ui/icon "search")
       [:input.cp__filters-input.w-full
       [:input.cp__filters-input.w-full
@@ -90,12 +90,12 @@
                         filtered-references)]
                         filtered-references)]
        (when (seq refs)
        (when (seq refs)
          [:div.mt-4
          [:div.mt-4
-          (filtered-refs page-name filters filters-atom refs)]))]))
+          (filtered-refs page-entity filters filters-atom refs)]))]))
 
 
 (defn filter-dialog
 (defn filter-dialog
-  [filters-atom *references page-name]
+  [page-entity filters-atom *references]
   (fn []
   (fn []
-    (filter-dialog-inner filters-atom *references page-name)))
+    (filter-dialog-inner page-entity filters-atom *references)))
 
 
 (rum/defc block-linked-references < rum/reactive db-mixins/query
 (rum/defc block-linked-references < rum/reactive db-mixins/query
   {:init (fn [state]
   {:init (fn [state]
@@ -136,7 +136,7 @@
      (content/content page-name {:hiccup ref-hiccup}))])
      (content/content page-name {:hiccup ref-hiccup}))])
 
 
 (rum/defc references-cp
 (rum/defc references-cp
-  [page-name filters filters-atom filter-state total filter-n filtered-ref-blocks *ref-pages]
+  [page-entity page-name filters filters-atom filter-state total filter-n filtered-ref-blocks *ref-pages]
   (let [threshold (state/get-linked-references-collapsed-threshold)
   (let [threshold (state/get-linked-references-collapsed-threshold)
         default-collapsed? (>= total threshold)
         default-collapsed? (>= total threshold)
         *collapsed? (atom nil)]
         *collapsed? (atom nil)]
@@ -152,7 +152,7 @@
         :on-pointer-down (fn [e]
         :on-pointer-down (fn [e]
                          (util/stop-propagation e))
                          (util/stop-propagation e))
         :on-click (fn []
         :on-click (fn []
-                    (state/set-modal! (filter-dialog filters-atom *ref-pages page-name)
+                    (state/set-modal! (filter-dialog page-entity filters-atom *ref-pages)
                                       {:center? true}))}
                                       {:center? true}))}
        (ui/icon "filter" {:class (cond
        (ui/icon "filter" {:class (cond
                                    (empty? filter-state)
                                    (empty? filter-state)
@@ -254,7 +254,7 @@
               [:div.references.page-linked.flex-1.flex-row
               [:div.references.page-linked.flex-1.flex-row
                (sub-page-properties-changed page-entity page-props-v filters-atom)
                (sub-page-properties-changed page-entity page-props-v filters-atom)
                [:div.content.pt-6
                [:div.content.pt-6
-                (references-cp page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
+                (references-cp page-entity page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
 
 
 (rum/defc references
 (rum/defc references
   [page-entity]
   [page-entity]

+ 4 - 3
src/main/frontend/components/right_sidebar.cljs

@@ -173,11 +173,12 @@
        (str init-key))]
        (str init-key))]
 
 
     :page-slide-view
     :page-slide-view
-    (let [page-name (:block/name (db/entity db-id))]
+    (let [page (db/entity db-id)
+          page-name (:block/name page)]
       [[:a.page-title {:href (rfe/href :page {:name page-name})}
       [[:a.page-title {:href (rfe/href :page {:name page-name})}
-        (db-model/get-page-original-name page-name)]
+        (:block/original-name page)]
        [:div.ml-2.slide.mt-2
        [:div.ml-2.slide.mt-2
-        (slide/slide page-name)]])
+        (slide/slide page)]])
 
 
     :shortcut-settings
     :shortcut-settings
     [[:.flex.items-center (ui/icon "command" {:class "text-md mr-2"}) (t :help/shortcuts)]
     [[:.flex.items-center (ui/icon "command" {:class "text-md mr-2"}) (t :help/shortcuts)]

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

@@ -530,11 +530,8 @@ independent of format as format specific heading characters are stripped"
        first))))
        first))))
 
 
 (defn get-page
 (defn get-page
-  [page-name]
-  (if-let [id (if (uuid? page-name) page-name
-                  (parse-uuid page-name))]
-    (db-utils/entity [:block/uuid id])
-    (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) (str page-name)))))
+  [page-name-or-uuid]
+  (ldb/get-page (conn/get-db) page-name-or-uuid))
 
 
 ;; FIXME: should pass page's db id
 ;; FIXME: should pass page's db id
 (defn get-redirect-page-name
 (defn get-redirect-page-name

+ 1 - 1
src/main/frontend/db_worker.cljs

@@ -383,7 +383,7 @@
          (when-not (and (:create-today-journal? tx-meta)
          (when-not (and (:create-today-journal? tx-meta)
                         (:today-journal-name tx-meta)
                         (:today-journal-name tx-meta)
                         (seq tx-data)
                         (seq tx-data)
-                        (d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
+                        (ldb/get-page @conn (:today-journal-name tx-meta))) ; today journal created already
 
 
            ;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
            ;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
            (worker-util/profile "Worker db transact"
            (worker-util/profile "Worker db transact"

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

@@ -88,10 +88,10 @@
                        (reset! *loading? false)
                        (reset! *loading? false)
                        (render!)))))
                        (render!)))))
                 state)}
                 state)}
-  [page-name]
-  (let [loading? (rum/react *loading?)
-        page (db/entity [:block/name page-name])
-        journal? (:journal? page)
+  [page]
+  (let [page-name (:block/original-name page)
+        loading? (rum/react *loading?)
+        journal? (:block/journal? page)
         repo (state/get-current-repo)
         repo (state/get-current-repo)
         blocks (-> (db/get-page-blocks-no-cache repo (:db/id page))
         blocks (-> (db/get-page-blocks-no-cache repo (:db/id page))
                    (outliner-tree/blocks->vec-tree (:db/id page)))
                    (outliner-tree/blocks->vec-tree (:db/id page)))

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

@@ -129,7 +129,7 @@
 
 
 (defn card-block?
 (defn card-block?
   [block]
   [block]
-  (let [card-entity (db/entity [:block/name card-hash-tag])
+  (let [card-entity (db/get-page card-hash-tag)
         refs (into #{} (:block/refs block))]
         refs (into #{} (:block/refs block))]
     (contains? refs card-entity)))
     (contains? refs card-entity)))
 
 
@@ -264,7 +264,7 @@
                        :or {use-cache? true}}]
                        :or {use-cache? true}}]
    (when (string? query-string)
    (when (string? query-string)
      (let [result (if (string/blank? query-string)
      (let [result (if (string/blank? query-string)
-                    (:block/_refs (db/entity [:block/name card-hash-tag]))
+                    (:block/_refs (db/get-page card-hash-tag))
                     (let [query-string (template/resolve-dynamic-template! query-string)
                     (let [query-string (template/resolve-dynamic-template! query-string)
                           query-string (if-not (or (string/blank? query-string)
                           query-string (if-not (or (string/blank? query-string)
                                                    (string/starts-with? query-string "(")
                                                    (string/starts-with? query-string "(")

+ 1 - 1
src/main/frontend/extensions/tldraw.cljs

@@ -115,7 +115,7 @@
    :getBlockPageName #(let [block-id-str %]
    :getBlockPageName #(let [block-id-str %]
                         (if (util/uuid-string? block-id-str)
                         (if (util/uuid-string? block-id-str)
                           (:block/name (model/get-block-page (state/get-current-repo) (parse-uuid block-id-str)))
                           (:block/name (model/get-block-page (state/get-current-repo) (parse-uuid block-id-str)))
-                          (:block/name (db/entity [:block/name (util/page-name-sanity-lc block-id-str)]))))
+                          (:block/name (db/get-page block-id-str))))
    :exportToImage (fn [page-uuid-str options]
    :exportToImage (fn [page-uuid-str options]
                     (assert (common-util/uuid-string? page-uuid-str))
                     (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}))))
                     (state/set-modal! #(export/export-blocks (uuid page-uuid-str) (merge (js->clj options :keywordize-keys true) {:whiteboard? true}))))

+ 2 - 2
src/main/frontend/handler/block.cljs

@@ -84,9 +84,9 @@
   [ref-blocks filters]
   [ref-blocks filters]
   (if (empty? filters)
   (if (empty? filters)
     ref-blocks
     ref-blocks
-    (let [exclude-ids (->> (keep (fn [page] (:db/id (db/entity [:block/name (util/page-name-sanity-lc page)]))) (get filters false))
+    (let [exclude-ids (->> (keep (fn [page] (:db/id (db/get-page page))) (get filters false))
                            (set))
                            (set))
-          include-ids (->> (keep (fn [page] (:db/id (db/entity [:block/name (util/page-name-sanity-lc page)]))) (get filters true))
+          include-ids (->> (keep (fn [page] (:db/id (db/get-page page))) (get filters true))
                            (set))]
                            (set))]
       (cond->> ref-blocks
       (cond->> ref-blocks
         (seq exclude-ids)
         (seq exclude-ids)

+ 6 - 8
src/main/frontend/handler/common/page.cljs

@@ -23,7 +23,6 @@
             [frontend.modules.outliner.ui :as ui-outliner-tx]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
             [frontend.modules.outliner.op :as outliner-op]))
             [frontend.modules.outliner.op :as outliner-op]))
 
 
-;; TODO: return page entity instead
 (defn create!
 (defn create!
   "Create page. Has the following options:
   "Create page. Has the following options:
 
 
@@ -43,11 +42,12 @@
    (let [repo (state/get-current-repo)
    (let [repo (state/get-current-repo)
          conn (db/get-db repo false)
          conn (db/get-db repo false)
          config (state/get-config repo)
          config (state/get-config repo)
+         ;; FIXME: create! returns page-entity
          [_ page-name] (worker-page/create! repo conn config title options)]
          [_ page-name] (worker-page/create! repo conn config title options)]
      (when redirect?
      (when redirect?
        ;; FIXME: use uuid instead
        ;; FIXME: use uuid instead
        (route-handler/redirect-to-page! page-name))
        (route-handler/redirect-to-page! page-name))
-     (when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
+     (when-let [first-block (first (:block/_left (db/get-page page-name)))]
        (block-handler/edit-block! first-block :max nil))
        (block-handler/edit-block! first-block :max nil))
      page-name)))
      page-name)))
 
 
@@ -65,7 +65,7 @@
      (when redirect?
      (when redirect?
        ;; FIXME: use uuid instead
        ;; FIXME: use uuid instead
        (route-handler/redirect-to-page! page-name))
        (route-handler/redirect-to-page! page-name))
-     (let [page (db/entity [:block/name page-name])]
+     (let [page (db/get-page page-name)]
        (when-let [first-block (first (:block/_left page))]
        (when-let [first-block (first (:block/_left page))]
          (block-handler/edit-block! first-block :max nil))
          (block-handler/edit-block! first-block :max nil))
        page))))
        page))))
@@ -120,14 +120,14 @@
 (defn <favorite-page!-v2
 (defn <favorite-page!-v2
   [page-block-uuid]
   [page-block-uuid]
   {:pre [(uuid? page-block-uuid)]}
   {:pre [(uuid? page-block-uuid)]}
-  (let [favorites-page (d/entity (conn/get-db) [:block/name common-config/favorites-page-name])]
+  (let [favorites-page (db/get-page common-config/favorites-page-name)]
     (when (d/entity (conn/get-db) [:block/uuid page-block-uuid])
     (when (d/entity (conn/get-db) [:block/uuid page-block-uuid])
       (p/do!
       (p/do!
        (when-not favorites-page (ldb/create-favorites-page (state/get-current-repo)))
        (when-not favorites-page (ldb/create-favorites-page (state/get-current-repo)))
        (ui-outliner-tx/transact!
        (ui-outliner-tx/transact!
         {:outliner-op :insert-blocks}
         {:outliner-op :insert-blocks}
         (outliner-op/insert-blocks! [(ldb/build-favorite-tx page-block-uuid)]
         (outliner-op/insert-blocks! [(ldb/build-favorite-tx page-block-uuid)]
-                                    (d/entity (conn/get-db) [:block/name common-config/favorites-page-name])
+                                    (db/get-page common-config/favorites-page-name)
                                     {}))))))
                                     {}))))))
 
 
 (defn <unfavorite-page!-v2
 (defn <unfavorite-page!-v2
@@ -170,9 +170,7 @@
   (let [repo-dir (config/get-repo-dir repo)]
   (let [repo-dir (config/get-repo-dir repo)]
       ;; TODO: move favorite && unfavorite to worker too
       ;; TODO: move favorite && unfavorite to worker too
     (if (config/db-based-graph? repo)
     (if (config/db-based-graph? repo)
-      (when-let [page-block-uuid (:block/uuid
-                                  (d/entity (conn/get-db repo)
-                                            [:block/name (common-util/page-name-sanity-lc page-name)]))]
+      (when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
         (<unfavorite-page!-v2 page-block-uuid))
         (<unfavorite-page!-v2 page-block-uuid))
       (unfavorite-page! page-name))
       (unfavorite-page! page-name))
 
 

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

@@ -178,7 +178,7 @@
     (let [tag-without-hash (common-util/safe-subs (string/trim v) 1)
     (let [tag-without-hash (common-util/safe-subs (string/trim v) 1)
           tag (or (page-ref/get-page-name tag-without-hash) tag-without-hash)]
           tag (or (page-ref/get-page-name tag-without-hash) tag-without-hash)]
       (when-not (string/blank? tag)
       (when-not (string/blank? tag)
-        (let [e (db/entity [:block/name (util/page-name-sanity-lc tag)])
+        (let [e (db/get-page tag)
               e' (if e
               e' (if e
                    (do
                    (do
                      (when-not (contains? (:block/type e) "tag")
                      (when-not (contains? (:block/type e) "tag")
@@ -453,7 +453,7 @@
   [block property value parse-block]
   [block property value parse-block]
   (let [current-page-id (:block/uuid (or (:block/page block) block))
   (let [current-page-id (:block/uuid (or (:block/page block) block))
         page-name (str "$$$" current-page-id)
         page-name (str "$$$" current-page-id)
-        page-entity (db/entity [:block/name page-name])
+        page-entity (db/get-page page-name)
         page (or page-entity
         page (or page-entity
                  (-> (block/page-name->map page-name true)
                  (-> (block/page-name->map page-name true)
                      (assoc :block/type #{"hidden"}
                      (assoc :block/type #{"hidden"}
@@ -505,7 +505,7 @@
   [block property template]
   [block property template]
   (let [current-page-id (:block/uuid (or (:block/page block) block))
   (let [current-page-id (:block/uuid (or (:block/page block) block))
         page-name (str "$$$" current-page-id)
         page-name (str "$$$" current-page-id)
-        page-entity (db/entity [:block/name page-name])
+        page-entity (db/get-page page-name)
         page (or page-entity
         page (or page-entity
                  (-> (block/page-name->map page-name true)
                  (-> (block/page-name->map page-name true)
                      (assoc :block/type #{"hidden"}
                      (assoc :block/type #{"hidden"}
@@ -532,7 +532,7 @@
 (defn- get-property-hidden-page
 (defn- get-property-hidden-page
   [property]
   [property]
   (let [page-name (str db-property-util/hidden-page-name-prefix (:block/uuid property))]
   (let [page-name (str db-property-util/hidden-page-name-prefix (:block/uuid property))]
-    (or (db/entity [:block/name page-name])
+    (or (db/get-page page-name)
         (db-property-util/build-property-hidden-page property))))
         (db-property-util/build-property-hidden-page property))))
 
 
 (defn re-init-commands!
 (defn re-init-commands!

+ 2 - 2
src/main/frontend/handler/editor.cljs

@@ -486,7 +486,7 @@
           sibling? (boolean sibling?)
           sibling? (boolean sibling?)
           sibling? (if before? true (if page false sibling?))
           sibling? (if before? true (if page false sibling?))
           block (if page
           block (if page
-                  (db/entity [:block/name (util/page-name-sanity-lc page)])
+                  (db/get-page page)
                   (db/entity [:block/uuid block-uuid]))
                   (db/entity [:block/uuid block-uuid]))
           db-based? (config/db-based-graph? repo)]
           db-based? (config/db-based-graph? repo)]
       (when block
       (when block
@@ -2268,7 +2268,7 @@
   (when id
   (when id
     (when-let [entity (if-let [id' (parse-uuid (str id))]
     (when-let [entity (if-let [id' (parse-uuid (str id))]
                         (db/entity [:block/uuid id'])
                         (db/entity [:block/uuid id'])
-                        (db/entity [:block/name (util/page-name-sanity-lc id)]))]
+                        (db/get-page id))]
       (= (:block/uuid entity) (otree/-get-parent-id current-node (db/get-db false))))))
       (= (:block/uuid entity) (otree/-get-parent-id current-node (db/get-db false))))))
 
 
 (defn insert
 (defn insert

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

@@ -694,13 +694,13 @@
 
 
 (defmethod handle :journal/insert-template [[_ page-name]]
 (defmethod handle :journal/insert-template [[_ page-name]]
   (let [page-name (util/page-name-sanity-lc page-name)]
   (let [page-name (util/page-name-sanity-lc page-name)]
-    (when-let [page (db/pull [:block/name page-name])]
+    (when-let [page (db/get-page page-name)]
       (when (db/page-empty? (state/get-current-repo) page-name)
       (when (db/page-empty? (state/get-current-repo) page-name)
         (when-let [template (state/get-default-journal-template)]
         (when-let [template (state/get-default-journal-template)]
           (editor-handler/insert-template!
           (editor-handler/insert-template!
-            nil
-            template
-            {:target page}))))))
+           nil
+           template
+           {:target page}))))))
 
 
 (defmethod handle :editor/set-org-mode-heading [[_ block heading]]
 (defmethod handle :editor/set-org-mode-heading [[_ block heading]]
   (when-let [id (:block/uuid block)]
   (when-let [id (:block/uuid block)]

+ 3 - 2
src/main/frontend/handler/export/opml.cljs

@@ -444,9 +444,10 @@
            (common/get-page-content root-block-uuids-or-page-uuid)
            (common/get-page-content root-block-uuids-or-page-uuid)
            (common/root-block-uuids->content repo 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)
          title (if (uuid? root-block-uuids-or-page-uuid)
-                 (:block/original-name (db/entity [:block/name root-block-uuids-or-page-uuid]))
+                 (:block/original-name (db/entity [:block/uuid root-block-uuids-or-page-uuid]))
                  "untitled")
                  "untitled")
-         first-block (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)])
+         first-block (and (coll? root-block-uuids-or-page-uuid)
+                          (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)]))
          format (or (:block/format first-block) (state/get-preferred-format))]
          format (or (:block/format first-block) (state/get-preferred-format))]
      (export-helper content format options :title title))))
      (export-helper content format options :title title))))
 
 

+ 35 - 36
src/main/frontend/handler/file_based/page_property.cljs

@@ -50,39 +50,38 @@
    content kvs))
    content kvs))
 
 
 (defn add-property!
 (defn add-property!
-  [page-name key value]
-  (let [repo (state/get-current-repo)]
-    (when-let [page (db/pull [:block/name (util/page-name-sanity-lc page-name)])]
-      (let [key (keyword key)
-            pre-block (db/get-pre-block repo (:db/id page))
-            format (state/get-preferred-format)
-            page-id {:db/id (:db/id page)}
-            org? (= format :org)
-            value (if (contains? #{:filters} key) (pr-str value) value)]
-        (if pre-block
-          (let [properties (:block/properties pre-block)
-                new-properties (assoc properties key value)
-                content (:block/content pre-block)
-                new-content (insert-property format content key value)
-                block {:db/id (:db/id pre-block)
-                       :block/properties new-properties
-                       :block/content new-content
-                       :block/page page-id}
-                tx [(assoc page-id :block/properties new-properties)
-                    block]]
-            (db/transact! tx))
-          (let [block {:block/uuid (db/new-block-id)
-                       :block/left page-id
-                       :block/parent page-id
-                       :block/page page-id
-                       :block/content (if org?
-                                        (str "#+" (string/upper-case (name key)) ": " value)
-                                        (str (name key) ":: " value))
-                       :block/format format
-                       :block/properties {key value}
-                       :block/pre-block? true}
-                page-properties-tx [(assoc page-id :block/properties {key value})]]
-            (ui-outliner-tx/transact!
-             {:outliner-op :insert-blocks
-              :additional-tx page-properties-tx}
-             (outliner-op/insert-blocks! block page {:sibling? false}))))))))
+  [page key value]
+  (let [repo (state/get-current-repo)
+        key (keyword key)
+        pre-block (db/get-pre-block repo (:db/id page))
+        format (state/get-preferred-format)
+        page-id {:db/id (:db/id page)}
+        org? (= format :org)
+        value (if (contains? #{:filters} key) (pr-str value) value)]
+    (if pre-block
+      (let [properties (:block/properties pre-block)
+            new-properties (assoc properties key value)
+            content (:block/content pre-block)
+            new-content (insert-property format content key value)
+            block {:db/id (:db/id pre-block)
+                   :block/properties new-properties
+                   :block/content new-content
+                   :block/page page-id}
+            tx [(assoc page-id :block/properties new-properties)
+                block]]
+        (db/transact! tx))
+      (let [block {:block/uuid (db/new-block-id)
+                   :block/left page-id
+                   :block/parent page-id
+                   :block/page page-id
+                   :block/content (if org?
+                                    (str "#+" (string/upper-case (name key)) ": " value)
+                                    (str (name key) ":: " value))
+                   :block/format format
+                   :block/properties {key value}
+                   :block/pre-block? true}
+            page-properties-tx [(assoc page-id :block/properties {key value})]]
+        (ui-outliner-tx/transact!
+         {:outliner-op :insert-blocks
+          :additional-tx page-properties-tx}
+         (outliner-op/insert-blocks! block page {:sibling? false}))))))

+ 1 - 1
src/main/frontend/handler/file_based/repo.cljs

@@ -88,7 +88,7 @@
                     default-content)
                     default-content)
           file-rpath (path/path-join (config/get-journals-directory) (str file-name "."
           file-rpath (path/path-join (config/get-journals-directory) (str file-name "."
                                                                           (config/get-file-extension format)))
                                                                           (config/get-file-extension format)))
-          page-exists? (db/entity repo-url [:block/name (util/page-name-sanity-lc title)])
+          page-exists? (db/page-exists? title)
           empty-blocks? (db/page-empty? repo-url (util/page-name-sanity-lc title))]
           empty-blocks? (db/page-empty? repo-url (util/page-name-sanity-lc title))]
       (when (or empty-blocks? (not page-exists?))
       (when (or empty-blocks? (not page-exists?))
         (p/let [_ (nfs/check-directory-permission! repo-url)
         (p/let [_ (nfs/check-directory-permission! repo-url)

+ 16 - 16
src/main/frontend/handler/import.cljs

@@ -101,21 +101,21 @@
       (p/do!
       (p/do!
        (when (not (db/page-exists? page-name))
        (when (not (db/page-exists? page-name))
          (page-handler/<create! page-name {:redirect? false}))
          (page-handler/<create! page-name {:redirect? false}))
-       (let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)])
-            children (:block/_parent page-block)
-            blocks (db/sort-by-left children page-block)
-            last-block (last blocks)
-            snd-last-block (last (butlast blocks))
-            [target-block sibling?] (if (and last-block (seq (:block/content last-block)))
-                                      [last-block true]
-                                      (if snd-last-block
-                                        [snd-last-block true]
-                                        [page-block false]))]
-        (editor/paste-blocks
-         parsed-blocks
-         {:target-block target-block
-          :sibling? sibling?})
-        (finished-ok-handler [page-name]))))))
+       (let [page-block (db/get-page page-name)
+             children (:block/_parent page-block)
+             blocks (db/sort-by-left children page-block)
+             last-block (last blocks)
+             snd-last-block (last (butlast blocks))
+             [target-block sibling?] (if (and last-block (seq (:block/content last-block)))
+                                       [last-block true]
+                                       (if snd-last-block
+                                         [snd-last-block true]
+                                         [page-block false]))]
+         (editor/paste-blocks
+          parsed-blocks
+          {:target-block target-block
+           :sibling? sibling?})
+         (finished-ok-handler [page-name]))))))
 
 
 (defn create-page-with-exported-tree!
 (defn create-page-with-exported-tree!
   "Create page from the per page object generated in `export-repo-as-edn-v2!`
   "Create page from the per page object generated in `export-repo-as-edn-v2!`
@@ -146,7 +146,7 @@
                                      "\nSkipped and continue the remaining import.") :error)))
                                      "\nSkipped and continue the remaining import.") :error)))
      (when has-children?
      (when has-children?
        (let [page-name (util/page-name-sanity-lc title)
        (let [page-name (util/page-name-sanity-lc title)
-             page-block (db/entity [:block/name page-name])]
+             page-block (db/get-page page-name)]
         ;; Missing support for per block format (or deprecated?)
         ;; Missing support for per block format (or deprecated?)
          (try (if whiteboard?
          (try (if whiteboard?
                ;; only works for file graph :block/properties
                ;; only works for file graph :block/properties

+ 18 - 22
src/main/frontend/handler/page.cljs

@@ -51,9 +51,8 @@
   (p/do!
   (p/do!
    (let [repo (state/get-current-repo)]
    (let [repo (state/get-current-repo)]
      (if (config/db-based-graph? repo)
      (if (config/db-based-graph? repo)
-       (let [db (conn/get-db)]
-         (when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
-           (page-common-handler/<unfavorite-page!-v2 page-block-uuid)))
+       (when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
+         (page-common-handler/<unfavorite-page!-v2 page-block-uuid))
        (page-common-handler/unfavorite-page! page-name)))
        (page-common-handler/unfavorite-page! page-name)))
    (state/update-favorites-updated!)))
    (state/update-favorites-updated!)))
 
 
@@ -62,9 +61,8 @@
   (p/do!
   (p/do!
    (let [repo (state/get-current-repo)]
    (let [repo (state/get-current-repo)]
      (if (config/db-based-graph? repo)
      (if (config/db-based-graph? repo)
-       (let [db (conn/get-db)]
-         (when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
-           (page-common-handler/<favorite-page!-v2 page-block-uuid)))
+       (when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
+         (page-common-handler/<favorite-page!-v2 page-block-uuid))
        (page-common-handler/favorite-page! page-name)))
        (page-common-handler/favorite-page! page-name)))
    (state/update-favorites-updated!)))
    (state/update-favorites-updated!)))
 
 
@@ -72,10 +70,9 @@
   [page-name]
   [page-name]
   (let [repo (state/get-current-repo)]
   (let [repo (state/get-current-repo)]
     (if (config/db-based-graph? repo)
     (if (config/db-based-graph? repo)
-      (when-let [db (conn/get-db)]
-        (boolean
-         (when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
-           (page-common-handler/favorited?-v2 page-block-uuid))))
+      (boolean
+       (when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
+         (page-common-handler/favorited?-v2 page-block-uuid)))
       (page-common-handler/favorited? page-name))))
       (page-common-handler/favorited? page-name))))
 
 
 
 
@@ -98,7 +95,7 @@
                               (filter string?)
                               (filter string?)
                               (mapv util/safe-page-name-sanity-lc)
                               (mapv util/safe-page-name-sanity-lc)
                               (distinct))]
                               (distinct))]
-          (keep (fn [page-name] (d/entity db [:block/name page-name])) page-names))))))
+          (keep (fn [page-name] (db/get-page page-name)) page-names))))))
 
 
 
 
 ;; FIXME: add whiteboard
 ;; FIXME: add whiteboard
@@ -151,12 +148,11 @@
   [favorites]
   [favorites]
   (let [conn (conn/get-db false)
   (let [conn (conn/get-db false)
         db @conn]
         db @conn]
-    (when-let [page-id (ldb/get-first-page-by-name db common-config/favorites-page-name)]
+    (when-let [page-id (db/get-page common-config/favorites-page-name)]
       (let [favorites-page-entity (d/entity db page-id)
       (let [favorites-page-entity (d/entity db page-id)
             favorite-page-block-db-id-coll
             favorite-page-block-db-id-coll
             (keep (fn [page-name]
             (keep (fn [page-name]
-                    (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
-                            :db/id))
+                    (:db/id (db/get-page page-name)))
                   favorites)
                   favorites)
             current-blocks (ldb/sort-by-left (ldb/get-page-blocks @conn common-config/favorites-page-name {})
             current-blocks (ldb/sort-by-left (ldb/get-page-blocks @conn common-config/favorites-page-name {})
                                              favorites-page-entity)]
                                              favorites-page-entity)]
@@ -179,8 +175,8 @@
     (state/set-journals-length! (+ (:journals-length @state/state) 7))))
     (state/set-journals-length! (+ (:journals-length @state/state) 7))))
 
 
 (defn update-public-attribute!
 (defn update-public-attribute!
-  [page-name value]
-  (property-handler/add-page-property! page-name :logseq.property/public value))
+  [page value]
+  (property-handler/add-page-property! page :logseq.property/public value))
 
 
 (defn get-page-ref-text
 (defn get-page-ref-text
   [page]
   [page]
@@ -262,8 +258,8 @@
              (log/error :syntax/filters e))))))
              (log/error :syntax/filters e))))))
 
 
 (defn save-filter!
 (defn save-filter!
-  [page-name filter-state]
-  (property-handler/add-page-property! page-name :logseq.property/filters filter-state))
+  [page filter-state]
+  (property-handler/add-page-property! page :logseq.property/filters filter-state))
 
 
 ;; Editor
 ;; Editor
 (defn page-not-exists-handler
 (defn page-not-exists-handler
@@ -286,7 +282,7 @@
       (cursor/move-cursor-forward input (+ 2 (count current-selected))))))
       (cursor/move-cursor-forward input (+ 2 (count current-selected))))))
 
 
 (defn add-tag [repo block-id tag & {:keys [tag-entity]}]
 (defn add-tag [repo block-id tag & {:keys [tag-entity]}]
-  (let [tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))
+  (let [tag-entity (or tag-entity (db/get-page tag))
         tx-data [[:db/add (:db/id tag-entity) :block/type "class"]
         tx-data [[:db/add (:db/id tag-entity) :block/type "class"]
                  [:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
                  [:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
                  ;; TODO: Should classes counted as refs
                  ;; TODO: Should classes counted as refs
@@ -330,12 +326,12 @@
              (let [tag (string/trim chosen)
              (let [tag (string/trim chosen)
                    edit-block (state/get-edit-block)]
                    edit-block (state/get-edit-block)]
                (when (and (not (string/blank? tag)) (:block/uuid edit-block))
                (when (and (not (string/blank? tag)) (:block/uuid edit-block))
-                 (p/let [tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])
+                 (p/let [tag-entity (db/get-page tag)
                          _ (when-not tag-entity
                          _ (when-not tag-entity
                              (<create! tag {:redirect? false
                              (<create! tag {:redirect? false
                                             :create-first-block? false
                                             :create-first-block? false
                                             :class? class?}))
                                             :class? class?}))
-                         tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])]
+                         tag-entity (db/get-page tag)]
                    (when class?
                    (when class?
                      (add-tag (state/get-current-repo) (:block/uuid edit-block) tag {:tag-entity tag-entity}))))))
                      (add-tag (state/get-current-repo) (:block/uuid edit-block) tag {:tag-entity tag-entity}))))))
            (editor-handler/insert-command! id
            (editor-handler/insert-command! id
@@ -404,7 +400,7 @@
 
 
 (defn open-today-in-sidebar
 (defn open-today-in-sidebar
   []
   []
-  (when-let [page (db/entity [:block/name (util/page-name-sanity-lc (date/today))])]
+  (when-let [page (db/get-page (date/today))]
     (state/sidebar-add-block!
     (state/sidebar-add-block!
      (state/get-current-repo)
      (state/get-current-repo)
      (:db/id page)
      (:db/id page)

+ 7 - 9
src/main/frontend/handler/property.cljs

@@ -4,9 +4,7 @@
             [frontend.handler.file-based.property :as file-property-handler]
             [frontend.handler.file-based.property :as file-property-handler]
             [frontend.handler.file-based.page-property :as file-page-property]
             [frontend.handler.file-based.page-property :as file-page-property]
             [frontend.config :as config]
             [frontend.config :as config]
-            [frontend.util :as util]
-            [frontend.state :as state]
-            [frontend.db :as db]))
+            [frontend.state :as state]))
 
 
 (defn remove-block-property!
 (defn remove-block-property!
   [repo block-id property-id-or-key]
   [repo block-id property-id-or-key]
@@ -26,12 +24,12 @@
 
 
 (defn add-page-property!
 (defn add-page-property!
   "Sanitized page-name, unsanitized key / value"
   "Sanitized page-name, unsanitized key / value"
-  [page-name key value]
-  (let [repo (state/get-current-repo)]
-    (if (config/db-based-graph? repo)
-      (when-let [page (db/entity [:block/name (util/page-name-sanity-lc page-name)])]
-       (set-block-property! repo (:block/uuid page) key value))
-      (file-page-property/add-property! page-name key value))))
+  [page-entity key value]
+  (when page-entity
+    (let [repo (state/get-current-repo)]
+      (if (config/db-based-graph? repo)
+        (set-block-property! repo (:block/uuid page-entity) key value)
+        (file-page-property/add-property! page-entity key value)))))
 
 
 (defn set-editing-new-property!
 (defn set-editing-new-property!
   [value]
   [value]

+ 4 - 4
src/main/frontend/handler/route.cljs

@@ -133,8 +133,8 @@
               (str (subs content 0 48) "...")
               (str (subs content 0 48) "...")
               content))
               content))
           "Page no longer exists!!")
           "Page no longer exists!!")
-        (let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
-          (or (util/get-page-original-name page)
+        (let [page (db/get-page name)]
+          (or (:block/original-name page)
               "Logseq"))))
               "Logseq"))))
     :whiteboard
     :whiteboard
     (let [name (:name path-params)
     (let [name (:name path-params)
@@ -142,8 +142,8 @@
       (str
       (str
        (if block?
        (if block?
          (t :untitled)
          (t :untitled)
-         (let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
-           (or (util/get-page-original-name page)
+         (let [page (db/get-page name)]
+           (or (:block/original-name page)
                "Logseq"))) " - " (t :whiteboard)))
                "Logseq"))) " - " (t :whiteboard)))
     :tag
     :tag
     (str "#"  (:name path-params))
     (str "#"  (:name path-params))

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

@@ -29,7 +29,7 @@
             :as opts}]
             :as opts}]
    (when-not (string/blank? q)
    (when-not (string/blank? q)
      (let [page-db-id (if (string? page-db-id)
      (let [page-db-id (if (string? page-db-id)
-                        (:db/id (db/entity repo [:block/name (util/page-name-sanity-lc page-db-id)]))
+                        (:db/id (db/get-page page-db-id))
                         page-db-id)
                         page-db-id)
            opts (if page-db-id (assoc opts :page (str page-db-id)) opts)]
            opts (if page-db-id (assoc opts :page (str page-db-id)) opts)]
        (p/let [blocks (search/block-search repo q opts)
        (p/let [blocks (search/block-search repo q opts)

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

@@ -315,11 +315,11 @@
   (when-let [app (state/active-tldraw-app)]
   (when-let [app (state/active-tldraw-app)]
     (let [tl-page ^js (second (first (.-pages app)))]
     (let [tl-page ^js (second (first (.-pages app)))]
       (when tl-page
       (when tl-page
-        (when-let [page (db/entity [:block/name page-name])]
-         (let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
-               shapes-index (:shapes-index page-metadata)]
-           (when (seq shapes-index)
-             (.updateShapesIndex tl-page (bean/->js shapes-index)))))))))
+        (when-let [page (db/get-page page-name)]
+          (let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
+                shapes-index (:shapes-index page-metadata)]
+            (when (seq shapes-index)
+              (.updateShapesIndex tl-page (bean/->js shapes-index)))))))))
 
 
 (defn populate-onboarding-whiteboard
 (defn populate-onboarding-whiteboard
   [api]
   [api]

+ 4 - 3
src/main/frontend/template.cljs

@@ -4,8 +4,9 @@
             [frontend.date :as date]
             [frontend.date :as date]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.db.utils :as db-utils]
             [frontend.db.utils :as db-utils]
-            [frontend.util :as util]
-            [logseq.common.util.page-ref :as page-ref]))
+            [logseq.common.util.page-ref :as page-ref]
+            [logseq.db :as ldb]
+            [frontend.db.conn :as conn]))
 
 
 (defn- variable-rules
 (defn- variable-rules
   []
   []
@@ -19,7 +20,7 @@
                     (let [block-uuid (parse-uuid current-page)
                     (let [block-uuid (parse-uuid current-page)
                           page (if block-uuid
                           page (if block-uuid
                                  (:block/page (db-utils/entity [:block/uuid block-uuid]))
                                  (:block/page (db-utils/entity [:block/uuid block-uuid]))
-                                 (db-utils/entity [:block/name (util/page-name-sanity-lc current-page)]))
+                                 (ldb/get-page (conn/get-db) current-page))
                           current-page' (:block/original-name page)]
                           current-page' (:block/original-name page)]
                       (page-ref/->page-ref current-page')))})
                       (page-ref/->page-ref current-page')))})
 
 

+ 4 - 5
src/main/frontend/util/page.cljs

@@ -15,13 +15,12 @@
   "Fetches the current page id. Looks up page based on latest route and if
   "Fetches the current page id. Looks up page based on latest route and if
   nothing is found, gets page of last edited block"
   nothing is found, gets page of last edited block"
   []
   []
-  (let [page-name (some-> (or (state/get-current-page) (state/get-current-whiteboard))
-                          util/page-name-sanity-lc)]
-    (or (and page-name (:db/id (db/entity [:block/name page-name])))
+  (let [page-name (or (state/get-current-page) (state/get-current-whiteboard))]
+    (or (and page-name (db/get-page page-name))
         (get-in (first (state/get-editor-args)) [:block :block/page :db/id]))))
         (get-in (first (state/get-editor-args)) [:block :block/page :db/id]))))
 
 
 (defn get-editing-page-id
 (defn get-editing-page-id
-  "Fetch the editing page id. If there is an edit-input-id set, we are probably still 
+  "Fetch the editing page id. If there is an edit-input-id set, we are probably still
    on editing mode"
    on editing mode"
   []
   []
   (if (or (state/editing?) (state/get-edit-input-id))
   (if (or (state/editing?) (state/get-edit-input-id))
@@ -36,4 +35,4 @@ Returns nil if no file path is found or no page is detected or given"
      (get-in (db/entity page-id) [:block/file :file/path])))
      (get-in (db/entity page-id) [:block/file :file/path])))
   ([page-name]
   ([page-name]
    (when-let [page-name' (some-> page-name util/page-name-sanity-lc)]
    (when-let [page-name' (some-> page-name util/page-name-sanity-lc)]
-     (get-in (db/entity [:block/name page-name']) [:block/file :file/path]))))
+     (get-in (db/get-page page-name') [:block/file :file/path]))))

+ 2 - 2
src/main/frontend/worker/export.cljs

@@ -38,9 +38,9 @@
               [?b :block/original-name]
               [?b :block/original-name]
               [?b :block/name]] db)
               [?b :block/name]] db)
 
 
-       (map (fn [[{:block/keys [name] :as page}]]
+       (map (fn [[page]]
               (let [whiteboard? (contains? (set (:block/type page)) "whiteboard")
               (let [whiteboard? (contains? (set (:block/type page)) "whiteboard")
-                    blocks (ldb/get-page-blocks db name {})
+                    blocks (ldb/get-page-blocks db (:db/id page) {})
                     blocks' (if whiteboard?
                     blocks' (if whiteboard?
                               blocks
                               blocks
                               (map (fn [b]
                               (map (fn [b]

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

@@ -71,7 +71,7 @@
                (not (worker-state/tx-idle? repo {:diff 3000})))
                (not (worker-state/tx-idle? repo {:diff 3000})))
         (async/put! file-writes-chan [repo page-db-id outliner-op (tc/to-long (t/now)) request-id])
         (async/put! file-writes-chan [repo page-db-id outliner-op (tc/to-long (t/now)) request-id])
         (let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
         (let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
-              blocks (ldb/get-page-blocks @conn (:block/name page-block) {:pull-keys pull-keys})
+              blocks (ldb/get-page-blocks @conn (:db/id page-block) {:pull-keys pull-keys})
               blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
               blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
           (if (and (= 1 (count blocks))
           (if (and (= 1 (count blocks))
                    (string/blank? (:block/content (first blocks)))
                    (string/blank? (:block/content (first blocks)))

+ 2 - 2
src/main/frontend/worker/rtc/core.cljs

@@ -475,8 +475,8 @@
 
 
 (defn- move-all-blocks-to-another-page
 (defn- move-all-blocks-to-another-page
   [repo conn from-page-name to-page-name]
   [repo conn from-page-name to-page-name]
-  (let [blocks (ldb/get-page-blocks @conn from-page-name {})
-        target-page-block (d/entity @conn (ldb/get-first-page-by-name @conn to-page-name))]
+  (let [blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn from-page-name)) {})
+        target-page-block (ldb/get-page @conn to-page-name)]
     (when (and (seq blocks) target-page-block)
     (when (and (seq blocks) target-page-block)
       (outliner-tx/transact!
       (outliner-tx/transact!
        {:persist-op? true
        {:persist-op? true

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

@@ -36,8 +36,8 @@
 ;;   (let [opts {:redirect? false :create-first-block? false}
 ;;   (let [opts {:redirect? false :create-first-block? false}
 ;;         _ (page-handler/create! "page1" opts)
 ;;         _ (page-handler/create! "page1" opts)
 ;;         _ (page-handler/create! "page2" opts)
 ;;         _ (page-handler/create! "page2" opts)
-;;         p1id (:block/uuid (db/entity [:block/name "page1"]))
-;;         p2id (:block/uuid (db/entity [:block/name "page2"]))]
+;;         p1id (:block/uuid (db/get-page "page1"))
+;;         p2id (:block/uuid (db/get-page "page2"))]
 ;;     (db-property-handler/upsert-property! repo "property-1" {:type :page} {})
 ;;     (db-property-handler/upsert-property! repo "property-1" {:type :page} {})
 ;;     (db-property-handler/set-block-property! repo fbid "property-1" p1id {})
 ;;     (db-property-handler/set-block-property! repo fbid "property-1" p1id {})
 ;;     (db-property-handler/set-block-property! repo sbid "property-1" p2id {})
 ;;     (db-property-handler/set-block-property! repo sbid "property-1" p2id {})
@@ -50,30 +50,30 @@
     (is (= ["Task" "card" "class1" "class2"] (sort (map first (model/get-all-classes repo)))))))
     (is (= ["Task" "card" "class1" "class2"] (sort (map first (model/get-all-classes repo)))))))
 
 
 (deftest get-class-objects-test
 (deftest get-class-objects-test
-    (let [opts {:redirect? false :create-first-block? false :class? true}
-          _ (page-handler/create! "class1" opts)
-          class (db/entity [:block/name "class1"])
-          _ (test-helper/save-block! repo fbid "Block 1" {:tags ["class1"]})]
-      (is (= (model/get-class-objects repo (:db/id class))
-             [(:db/id (db/entity [:block/uuid fbid]))]))
+  (let [opts {:redirect? false :create-first-block? false :class? true}
+        _ (page-handler/create! "class1" opts)
+        class (db/get-page "class1")
+        _ (test-helper/save-block! repo fbid "Block 1" {:tags ["class1"]})]
+    (is (= (model/get-class-objects repo (:db/id class))
+           [(:db/id (db/entity [:block/uuid fbid]))]))
 
 
-      (testing "classes parent"
-        (page-handler/create! "class2" opts)
+    (testing "classes parent"
+      (page-handler/create! "class2" opts)
       ;; set class2's parent to class1
       ;; set class2's parent to class1
-        (let [class2 (db/entity [:block/name "class2"])]
-          (db/transact! [{:db/id (:db/id class2)
-                          :class/parent (:db/id class)}]))
-        (test-helper/save-block! repo sbid "Block 2" {:tags ["class2"]})
-        (is (= (model/get-class-objects repo (:db/id class))
-               [(:db/id (db/entity [:block/uuid fbid]))
-                (:db/id (db/entity [:block/uuid sbid]))])))))
+      (let [class2 (db/get-page "class2")]
+        (db/transact! [{:db/id (:db/id class2)
+                        :class/parent (:db/id class)}]))
+      (test-helper/save-block! repo sbid "Block 2" {:tags ["class2"]})
+      (is (= (model/get-class-objects repo (:db/id class))
+             [(:db/id (db/entity [:block/uuid fbid]))
+              (:db/id (db/entity [:block/uuid sbid]))])))))
 
 
 (deftest get-classes-with-property-test
 (deftest get-classes-with-property-test
   (let [opts {:redirect? false :create-first-block? false :class? true}
   (let [opts {:redirect? false :create-first-block? false :class? true}
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class2" opts)
         _ (page-handler/create! "class2" opts)
-        class1 (db/entity [:block/name "class1"])
-        class2 (db/entity [:block/name "class2"])]
+        class1 (db/get-page "class1")
+        class2 (db/get-page "class2")]
     (db-property-handler/upsert-property! repo :user.property/property-1 {:type :page} {})
     (db-property-handler/upsert-property! repo :user.property/property-1 {:type :page} {})
     (db-property-handler/class-add-property! repo (:block/uuid class1) :user.property/property-1)
     (db-property-handler/class-add-property! repo (:block/uuid class1) :user.property/property-1)
     (db-property-handler/class-add-property! repo (:block/uuid class2) :user.property/property-1)
     (db-property-handler/class-add-property! repo (:block/uuid class2) :user.property/property-1)
@@ -95,7 +95,7 @@
 (deftest hidden-page-test
 (deftest hidden-page-test
   (let [opts {:redirect? false :create-first-block? false}
   (let [opts {:redirect? false :create-first-block? false}
         _ (page-handler/create! "page 1" opts)]
         _ (page-handler/create! "page 1" opts)]
-    (is (false? (model/hidden-page? (db/entity [:block/name "page 1"]))))
+    (is (false? (model/hidden-page? (db/get-page "page 1"))))
     (is (true? (model/hidden-page? "$$$test")))
     (is (true? (model/hidden-page? "$$$test")))
     (is (true? (model/hidden-page? (str "$$$" (random-uuid)))))))
     (is (true? (model/hidden-page? (str "$$$" (random-uuid)))))))
 
 
@@ -104,13 +104,13 @@
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class2" opts)
         _ (page-handler/create! "class2" opts)
         _ (page-handler/create! "class3" opts)
         _ (page-handler/create! "class3" opts)
-        class1 (db/entity [:block/name "class1"])
-        class2 (db/entity [:block/name "class2"])
-        class3 (db/entity [:block/name "class3"])
+        class1 (db/get-page "class1")
+        class2 (db/get-page "class2")
+        class3 (db/get-page "class3")
         _ (db/transact! [{:db/id (:db/id class2)
         _ (db/transact! [{:db/id (:db/id class2)
                           :class/parent (:db/id class1)}
                           :class/parent (:db/id class1)}
                          {:db/id (:db/id class3)
                          {:db/id (:db/id class3)
                           :class/parent (:db/id class2)}])]
                           :class/parent (:db/id class2)}])]
     (is
     (is
-     (= (model/get-class-children repo (:db/id (db/entity [:block/name "class1"])))
+     (= (model/get-class-children repo (:db/id (db/get-page "class1")))
         [(:db/id class2) (:db/id class3)]))))
         [(:db/id class2) (:db/id class3)]))))

+ 5 - 5
src/test/frontend/handler/db_based/property_test.cljs

@@ -161,16 +161,16 @@
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class1" opts)
         _ (page-handler/create! "class2" opts)
         _ (page-handler/create! "class2" opts)
         _ (page-handler/create! "class3" opts)
         _ (page-handler/create! "class3" opts)
-        c1 (db/entity [:block/name "class1"])
-        c2 (db/entity [:block/name "class2"])
+        c1 (db/get-page "class1")
+        c2 (db/get-page "class2")
         c1id (:block/uuid c1)
         c1id (:block/uuid c1)
         c2id (:block/uuid c2)]
         c2id (:block/uuid c2)]
 
 
     (testing "Create classes"
     (testing "Create classes"
       (are [x y] (= x y)
       (are [x y] (= x y)
-        (:block/type (db/entity [:block/name "class1"]))
+        (:block/type (db/get-page "class1"))
         #{"class"}
         #{"class"}
-        (:block/type (db/entity [:block/name "class2"]))
+        (:block/type (db/get-page "class2"))
         #{"class"}))
         #{"class"}))
 
 
     (testing "Class add property"
     (testing "Class add property"
@@ -194,7 +194,7 @@
         (is (= 2 (count (:block/tags (db/entity [:block/uuid fbid]))))))
         (is (= 2 (count (:block/tags (db/entity [:block/uuid fbid]))))))
     (testing "Get block's classes properties"
     (testing "Get block's classes properties"
       ;; set c2 as parent of c3
       ;; set c2 as parent of c3
-      (let [c3 (db/entity [:block/name "class3"])]
+      (let [c3 (db/get-page "class3")]
         (db/transact! [{:db/id (:db/id c3)
         (db/transact! [{:db/id (:db/id c3)
                         :class/parent (:db/id c2)}]))
                         :class/parent (:db/id c2)}]))
       (db-property-handler/class-add-property! repo c2id :user.property/property-3)
       (db-property-handler/class-add-property! repo c2id :user.property/property-3)

+ 7 - 3
src/test/frontend/handler/editor_test.cljs

@@ -295,7 +295,9 @@
 -"}])
 -"}])
     (let [conn (db/get-db test-helper/test-db false)
     (let [conn (db/get-db test-helper/test-db false)
           block (->> (d/q '[:find (pull ?b [*])
           block (->> (d/q '[:find (pull ?b [*])
-                            :where [?b :block/content ""] [?b :block/page [:block/name "page1"]]]
+                            :where [?b :block/content ""]
+                                   [?p :block/name "page1"]
+                                   [?b :block/page ?p]]
                           @conn)
                           @conn)
                      ffirst)
                      ffirst)
           _ (delete-block @conn block {})
           _ (delete-block @conn block {})
@@ -316,7 +318,9 @@
 -"}])
 -"}])
     (let [conn (db/get-db test-helper/test-db false)
     (let [conn (db/get-db test-helper/test-db false)
           block (->> (d/q '[:find (pull ?b [*])
           block (->> (d/q '[:find (pull ?b [*])
-                            :where [?b :block/content ""] [?b :block/page [:block/name "page1"]]]
+                            :where [?b :block/content ""]
+                                   [?p :block/name "page1"]
+                                   [?b :block/page ?p]]
                           @conn)
                           @conn)
                      ffirst)
                      ffirst)
           _ (delete-block @conn block {:embed? true})
           _ (delete-block @conn block {:embed? true})
@@ -324,4 +328,4 @@
                                      :where [?b :block/content] [(missing? $ ?b :block/pre-block?)]]
                                      :where [?b :block/content] [(missing? $ ?b :block/pre-block?)]]
                                    @conn)
                                    @conn)
                               (map (comp :block/content first)))]
                               (map (comp :block/content first)))]
-      (is (= ["b1" "b2"] updated-blocks) "Block is deleted"))))
+      (is (= ["b1" "b2"] updated-blocks) "Block is deleted"))))

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

@@ -26,25 +26,25 @@
 
 
 (deftest rename-test
 (deftest rename-test
   (testing "Case change"
   (testing "Case change"
-    (let [page (db/entity [:block/name "test"])]
+    (let [page (db/get-page "test")]
       (page-rename "test" "Test")
       (page-rename "test" "Test")
-      (let [entity (db/entity [:block/name "test"])]
+      (let [entity (db/get-page "test")]
         (is (= "Test" (:block/original-name entity)))
         (is (= "Test" (:block/original-name entity)))
         ;; db id not changed
         ;; db id not changed
         (is (= (:db/id page) (:db/id entity))))))
         (is (= (:db/id page) (:db/id entity))))))
 
 
   (testing "Name changed"
   (testing "Name changed"
-    (let [page (db/entity [:block/name "test"])]
+    (let [page (db/get-page "test")]
       (page-rename "Test" "New name")
       (page-rename "Test" "New name")
-      (let [entity (db/entity [:block/name "new name"])]
+      (let [entity (db/get-page "new name")]
         (is (= "New name" (:block/original-name entity)))
         (is (= "New name" (:block/original-name entity)))
         (is (= (:db/id page) (:db/id entity))))))
         (is (= (:db/id page) (:db/id entity))))))
 
 
   ;; (testing "Merge existing page"
   ;; (testing "Merge existing page"
   ;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
   ;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
   ;;   (page-rename "New name" "Existing page")
   ;;   (page-rename "New name" "Existing page")
-  ;;   (let [e1 (db/entity [:block/name "new name"])
-  ;;         e2 (db/entity [:block/name "existing page"])]
+  ;;   (let [e1 (db/get-page "new name")
+  ;;         e2 (db/get-page "existing page")]
   ;;     ;; Old page deleted
   ;;     ;; Old page deleted
   ;;     (is (nil? e1))
   ;;     (is (nil? e1))
   ;;     ;; Blocks from both pages have been merged
   ;;     ;; Blocks from both pages have been merged
@@ -56,8 +56,8 @@
 ;; (deftest merge-with-empty-page
 ;; (deftest merge-with-empty-page
 ;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? false})
 ;;   (page-handler/create! "Existing page" {:redirect? false :create-first-block? false})
 ;;   (page-rename "Test" "Existing page")
 ;;   (page-rename "Test" "Existing page")
-;;   (let [e1 (db/entity [:block/name "test"])
-;;         e2 (db/entity [:block/name "existing page"])]
+;;   (let [e1 (db/get-page "test")
+;;         e2 (db/get-page "existing page")]
 ;;       ;; Old page deleted
 ;;       ;; Old page deleted
 ;;     (is (nil? e1))
 ;;     (is (nil? e1))
 ;;       ;; Blocks from both pages have been merged
 ;;       ;; Blocks from both pages have been merged
@@ -70,8 +70,8 @@
 ;;     (editor-handler/save-block! repo fbid "Block 1 [[Test]]")
 ;;     (editor-handler/save-block! repo fbid "Block 1 [[Test]]")
 ;;     (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
 ;;     (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
 ;;     (page-rename "Test" "Existing page")
 ;;     (page-rename "Test" "Existing page")
-;;     (let [e1 (db/entity [:block/name "test"])
-;;           e2 (db/entity [:block/name "existing page"])]
+;;     (let [e1 (db/get-page "test")
+;;           e2 (db/get-page "existing page")]
 ;;       ;; Old page deleted
 ;;       ;; Old page deleted
 ;;       (is (nil? e1))
 ;;       (is (nil? e1))
 ;;       ;; Blocks from both pages have been merged
 ;;       ;; Blocks from both pages have been merged

+ 1 - 1
src/test/frontend/worker/pipeline_test.cljs

@@ -25,7 +25,7 @@
     (let [conn (db/get-db test-helper/test-db false)
     (let [conn (db/get-db test-helper/test-db false)
           blocks (get-blocks @conn)
           blocks (get-blocks @conn)
           ;; Update parent block to replace #foo with #bar
           ;; Update parent block to replace #foo with #bar
-          new-tag-id (:db/id (d/entity @conn [:block/name "bar"]))
+          new-tag-id (:db/id (db/get-page "bar"))
           modified-blocks (map #(if (= "parent #foo" (:block/content %))
           modified-blocks (map #(if (= "parent #foo" (:block/content %))
                                   (assoc %
                                   (assoc %
                                          :block/refs [{:db/id new-tag-id}]
                                          :block/refs [{:db/id new-tag-id}]

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

@@ -54,7 +54,7 @@
          {:block/uuid uuid2 :block/content "uuid2-client"
          {:block/uuid uuid2 :block/content "uuid2-client"
           :block/left [:block/uuid uuid1]
           :block/left [:block/uuid uuid1]
           :block/parent [:block/uuid page1-uuid]}]
           :block/parent [:block/uuid page1-uuid]}]
-        (d/pull @conn '[*] [:block/name page1-name])
+        (ldb/get-page @conn page1-name)
         {:sibling? true :keep-uuid? true}))
         {:sibling? true :keep-uuid? true}))
       (let [ops (gen-ops-fn)]
       (let [ops (gen-ops-fn)]
         (is (= #{[:move uuid1 page1-uuid]
         (is (= #{[:move uuid1 page1-uuid]

+ 3 - 2
src/test/frontend/worker/rtc/rtc_effects_test.cljs

@@ -15,6 +15,7 @@
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.transaction :as outliner-tx]
             [logseq.outliner.transaction :as outliner-tx]
+            [logseq.db :as ldb]
             [spy.core :as spy]))
             [spy.core :as spy]))
 
 
 (use-fixtures :each
 (use-fixtures :each
@@ -48,7 +49,7 @@
           conn (conn/get-db repo false)]
           conn (conn/get-db repo false)]
       (page-handler/create! "gen-local-ops-test-2--create-page&insert-blocks"
       (page-handler/create! "gen-local-ops-test-2--create-page&insert-blocks"
                             {:redirect? false :create-first-block? false})
                             {:redirect? false :create-first-block? false})
-      (let [page-block (d/pull @conn '[*] [:block/name "gen-local-ops-test-2--create-page&insert-blocks"])
+      (let [page-block (ldb/get-page @conn "gen-local-ops-test-2--create-page&insert-blocks")
             [block-uuid1 block-uuid2] (repeatedly random-uuid)]
             [block-uuid1 block-uuid2] (repeatedly random-uuid)]
         (outliner-tx/transact!
         (outliner-tx/transact!
          {:transact-opts {:repo repo
          {:transact-opts {:repo repo
@@ -97,7 +98,7 @@
          (<! (timeout 500))
          (<! (timeout 500))
          (is (= {:block/uuid #uuid "26c4b513-e251-4ce9-a421-364b774eb736"
          (is (= {:block/uuid #uuid "26c4b513-e251-4ce9-a421-364b774eb736"
                  :block/original-name "Push-Data-From-Ws-Test-1"}
                  :block/original-name "Push-Data-From-Ws-Test-1"}
-                (select-keys (d/pull @conn '[*] [:block/name "push-data-from-ws-test-1"])
+                (select-keys (ldb/get-page @conn "push-data-from-ws-test-1")
                              [:block/uuid :block/original-name])))
                              [:block/uuid :block/original-name])))
          (reset)
          (reset)
          (done))))))
          (done))))))

+ 21 - 20
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -93,14 +93,14 @@
        {:block/uuid uuid4 :block/content "uuid4-block"
        {:block/uuid uuid4 :block/content "uuid4-block"
         :block/left [:block/uuid uuid3]
         :block/left [:block/uuid uuid3]
         :block/parent [:block/uuid uuid1]}]
         :block/parent [:block/uuid uuid1]}]
-      (d/pull @conn '[*] [:block/name "gen-remote-ops-test"])
+      (ldb/get-page @conn  "gen-remote-ops-test")
       {:sibling? true :keep-uuid? true}))
       {:sibling? true :keep-uuid? true}))
 
 
     (op-mem-layer/init-empty-ops-store! repo)
     (op-mem-layer/init-empty-ops-store! repo)
     (op-mem-layer/add-ops! repo [["move" {:block-uuid (str uuid2) :epoch 1}]
     (op-mem-layer/add-ops! repo [["move" {:block-uuid (str uuid2) :epoch 1}]
-                                         ["move" {:block-uuid (str uuid4) :epoch 2}]
-                                         ["move" {:block-uuid (str uuid3) :epoch 3}]
-                                         ["update" {:block-uuid (str uuid4) :epoch 4}]])
+                                 ["move" {:block-uuid (str uuid4) :epoch 2}]
+                                 ["move" {:block-uuid (str uuid3) :epoch 3}]
+                                 ["update" {:block-uuid (str uuid4) :epoch 4}]])
     (let [_ (op-mem-layer/new-branch! repo)
     (let [_ (op-mem-layer/new-branch! repo)
           r1 (rtc-core/gen-block-uuid->remote-ops repo conn "user-uuid" :n 1)
           r1 (rtc-core/gen-block-uuid->remote-ops repo conn "user-uuid" :n 1)
           _ (op-mem-layer/rollback! repo)
           _ (op-mem-layer/rollback! repo)
@@ -137,7 +137,7 @@
        {:block/uuid uuid2-client :block/content "uuid2-client"
        {:block/uuid uuid2-client :block/content "uuid2-client"
         :block/left [:block/uuid uuid1-client]
         :block/left [:block/uuid uuid1-client]
         :block/parent [:block/uuid page-uuid]}]
         :block/parent [:block/uuid page-uuid]}]
-      (d/pull @conn '[*] [:block/name page-name])
+      (ldb/get-page @conn page-name)
       {:sibling? true :keep-uuid? true}))
       {:sibling? true :keep-uuid? true}))
     (testing "apply-remote-move-ops-test1"
     (testing "apply-remote-move-ops-test1"
       (let [data-from-ws {:req-id "req-id"
       (let [data-from-ws {:req-id "req-id"
@@ -155,7 +155,7 @@
                         repo (:affected-blocks data-from-ws))))]
                         repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
         (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
           (is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))
           (is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))
 
 
@@ -179,7 +179,7 @@
                         repo (:affected-blocks data-from-ws))))]
                         repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
         (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-remote uuid2-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1-remote uuid2-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
           (is (= uuid1-client (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid2-remote])))))
           (is (= uuid1-client (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid2-remote])))))
           (is (= uuid2-remote (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))))
           (is (= uuid2-remote (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))))
@@ -210,7 +210,7 @@
        {:block/uuid uuid2-client :block/content "uuid2-client"
        {:block/uuid uuid2-client :block/content "uuid2-client"
         :block/left [:block/uuid uuid1-client]
         :block/left [:block/uuid uuid1-client]
         :block/parent [:block/uuid page-uuid]}]
         :block/parent [:block/uuid page-uuid]}]
-      (d/pull @conn '[*] [:block/name page-name])
+      (ldb/get-page @conn page-name)
       {:sibling? true :keep-uuid? true}))
       {:sibling? true :keep-uuid? true}))
     (testing "apply-remote-update-ops-test1"
     (testing "apply-remote-update-ops-test1"
       (let [data-from-ws {:req-id "req-id"
       (let [data-from-ws {:req-id "req-id"
@@ -230,7 +230,7 @@
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= [uuid1-client #{"property"}]
           (is (= [uuid1-client #{"property"}]
                  ((juxt (comp :block/uuid :block/link) :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
                  ((juxt (comp :block/uuid :block/link) :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
@@ -253,7 +253,7 @@
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
           (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
     (testing "apply-remote-update-ops-test3"
     (testing "apply-remote-update-ops-test3"
@@ -270,7 +270,7 @@
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
         (rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
           (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
           (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
     (testing "update-attr :block/tags"
     (testing "update-attr :block/tags"
@@ -317,7 +317,7 @@
        {:block/uuid uuid2-client :block/content "uuid2-client"
        {:block/uuid uuid2-client :block/content "uuid2-client"
         :block/left [:block/uuid uuid1-client]
         :block/left [:block/uuid uuid1-client]
         :block/parent [:block/uuid page-uuid]}]
         :block/parent [:block/uuid page-uuid]}]
-      (d/pull @conn '[*] [:block/name page-name])
+      (ldb/get-page @conn page-name)
       {:sibling? true :keep-uuid? true}))
       {:sibling? true :keep-uuid? true}))
     (testing "apply-remote-remove-ops-test1"
     (testing "apply-remote-remove-ops-test1"
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
@@ -330,7 +330,7 @@
               (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
               (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1-client uuid2-client} (set (map :block/uuid page-blocks)))))))
           (is (= #{uuid1-client uuid2-client} (set (map :block/uuid page-blocks)))))))
     (testing "apply-remote-remove-ops-test2"
     (testing "apply-remote-remove-ops-test2"
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
@@ -342,7 +342,7 @@
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
                          (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid2-client} (set (map :block/uuid page-blocks)))))))))
           (is (= #{uuid2-client} (set (map :block/uuid page-blocks)))))))))
 
 
 (deftest apply-remote-remove-ops-test2
 (deftest apply-remote-remove-ops-test2
@@ -384,7 +384,7 @@ server: ;; remove 2
          {:block/uuid uuid3 :block/content "3"
          {:block/uuid uuid3 :block/content "3"
           :block/left [:block/uuid uuid2]
           :block/left [:block/uuid uuid2]
           :block/parent [:block/uuid uuid2]}]
           :block/parent [:block/uuid uuid2]}]
-        (d/pull @conn '[*] [:block/name page-name])
+        (ldb/get-page @conn page-name)
         {:sibling? false :keep-uuid? true}))
         {:sibling? false :keep-uuid? true}))
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
       (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
                           :affected-blocks
                           :affected-blocks
@@ -396,7 +396,7 @@ server: ;; remove 2
               (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
               (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (is (rtc-const/data-from-ws-validator data-from-ws))
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
         (rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
-        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+        (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
           (is (= #{uuid1 uuid3} (set (map :block/uuid page-blocks))))
           (is (= #{uuid1 uuid3} (set (map :block/uuid page-blocks))))
           (is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid3]))))))))))
           (is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid3]))))))))))
 
 
@@ -473,7 +473,7 @@ server: ;; remove 2
         :block/content "uuid2-client"
         :block/content "uuid2-client"
         :block/left [:block/uuid uuid1-client]
         :block/left [:block/uuid uuid1-client]
         :block/parent [:block/uuid page1-uuid]}]
         :block/parent [:block/uuid page1-uuid]}]
-      (d/pull @conn '[*] [:block/name page-name])
+      (ldb/get-page @conn page-name)
       {:sibling? true :keep-uuid? true}))
       {:sibling? true :keep-uuid? true}))
     (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
     (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
                         :affected-blocks
                         :affected-blocks
@@ -497,6 +497,7 @@ server: ;; remove 2
       (is (rtc-const/data-from-ws-validator 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)
       (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
       (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
       (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
-      (is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
-             (set (map :block/uuid (ldb/get-page-blocks @conn page-name {})))))
-      (is (= page2-uuid (:block/uuid (d/entity @conn [:block/name page-name])))))))
+      (let [page (ldb/get-page @conn page-name)]
+        (is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
+             (set (map :block/uuid (ldb/get-page-blocks @conn (:db/id page) {})))))
+        (is (= page2-uuid (:block/uuid page)))))))