Kaynağa Gözat

fix: pages didn't consistenly have :block/format

Making attributes consistent reduce bugs in components and query layer (where
most wouldn't know to use get-else)
Gabriel Horner 2 yıl önce
ebeveyn
işleme
e09a5d9988

+ 13 - 11
deps/db/src/logseq/db.cljs

@@ -9,19 +9,21 @@
 (defn create-default-pages!
 (defn create-default-pages!
   "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 {:keys [db-graph?]}]
   (when-not (d/entity @db-conn [:block/name "card"])
   (when-not (d/entity @db-conn [:block/name "card"])
     (let [time (tc/to-long (t/now))
     (let [time (tc/to-long (t/now))
-          built-in-pages-with-timestamp (map
-                                          (fn [m]
-                                            (-> m
-                                                (assoc :block/created-at time)
-                                                (assoc :block/updated-at time)))
-                                          default-db/built-in-pages)]
+          built-in-pages (map
+                          (fn [m]
+                            (cond-> (-> m
+                                        (assoc :block/created-at time)
+                                        (assoc :block/updated-at time))
+                              db-graph?
+                              (assoc :block/format :markdown)))
+                          default-db/built-in-pages)]
       (d/transact! db-conn
       (d/transact! db-conn
-       (concat
-        [{:schema/version db-schema/version}]
-        built-in-pages-with-timestamp)))))
+                   (concat
+                    [{:schema/version db-schema/version}]
+                    built-in-pages)))))
 
 
 (defn start-conn
 (defn start-conn
   "Create datascript conn with schema and default data"
   "Create datascript conn with schema and default data"
@@ -30,5 +32,5 @@
            schema db-schema/schema}}]
            schema db-schema/schema}}]
   (let [db-conn (d/create-conn schema)]
   (let [db-conn (d/create-conn schema)]
     (when create-default-pages?
     (when create-default-pages?
-      (create-default-pages! db-conn))
+      (create-default-pages! db-conn {}))
     db-conn))
     db-conn))

+ 2 - 5
deps/db/src/logseq/db/malli_schema.cljs

@@ -66,8 +66,8 @@
   [[:block/uuid :uuid]
   [[:block/uuid :uuid]
    [:block/created-at :int]
    [:block/created-at :int]
    [:block/updated-at :int]
    [:block/updated-at :int]
-   [:block/properties {:optional true}
-    block-properties]
+   [:block/properties {:optional true} block-properties]
+   [:block/format [:enum :markdown]]
    [:block/refs {:optional true} [:set :int]]
    [:block/refs {:optional true} [:set :int]]
    [:block/tags {:optional true} [:set :int]]
    [:block/tags {:optional true} [:set :int]]
    [:block/tx-id {:optional true} :int]])
    [:block/tx-id {:optional true} :int]])
@@ -78,8 +78,6 @@
    [:block/original-name :string]
    [:block/original-name :string]
    [:block/type {:optional true} [:enum #{"property"} #{"class"} #{"object"} #{"whiteboard"} #{"hidden"}]]
    [:block/type {:optional true} [:enum #{"property"} #{"class"} #{"object"} #{"whiteboard"} #{"hidden"}]]
    [:block/journal? :boolean]
    [:block/journal? :boolean]
-    ;; TODO: Consider moving to just normal and class after figuring out journal attributes
-   [:block/format {:optional true} [:enum :markdown]]
     ;; TODO: Should this be here or in common?
     ;; TODO: Should this be here or in common?
    [:block/path-refs {:optional true} [:set :int]]])
    [:block/path-refs {:optional true} [:set :int]]])
 
 
@@ -192,7 +190,6 @@
    [:block/path-refs {:optional true} [:set :int]]
    [:block/path-refs {:optional true} [:set :int]]
    [:block/link {:optional true} :int]
    [:block/link {:optional true} :int]
     ;; other
     ;; other
-   [:block/format [:enum :markdown]]
    [:block/marker {:optional true} :string]
    [:block/marker {:optional true} :string]
    [:block/priority {:optional true} :string]
    [:block/priority {:optional true} :string]
    [:block/collapsed? {:optional true} :boolean]])
    [:block/collapsed? {:optional true} :boolean]])

+ 2 - 1
deps/db/src/logseq/db/sqlite/util.cljs

@@ -89,7 +89,8 @@
   [block]
   [block]
   (block-with-timestamps
   (block-with-timestamps
    (merge {:block/type "property"
    (merge {:block/type "property"
-           :block/journal? false}
+           :block/journal? false
+           :block/format :markdown}
           block)))
           block)))
 
 
 (defn build-db-initial-data
 (defn build-db-initial-data

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

@@ -594,8 +594,11 @@
         block (if (seq timestamps)
         block (if (seq timestamps)
                 (merge block (timestamps->scheduled-and-deadline timestamps))
                 (merge block (timestamps->scheduled-and-deadline timestamps))
                 block)
                 block)
-        block (assoc block :body body)
-        block (with-page-block-refs block with-id? db date-formatter)
+        block (-> block
+                  (assoc :body body)
+                  (with-page-block-refs with-id? db date-formatter)
+                  (update :tags (fn [tags] (map #(assoc % :block/format format) tags)))
+                  (update :refs (fn [refs] (map #(if (map? %) (assoc % :block/format format) %) refs))))
         block (update block :refs concat (:block-refs properties))
         block (update block :refs concat (:block-refs properties))
         {:keys [created-at updated-at]} (:properties properties)
         {:keys [created-at updated-at]} (:properties properties)
         block (cond-> block
         block (cond-> block

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

@@ -106,7 +106,7 @@
                 (into {})))
                 (into {})))
         "Task marker counts")
         "Task marker counts")
 
 
-    (is (= {:markdown 5499 :org 457} (get-block-format-counts db))
+    (is (= {:markdown 6106 :org 509} (get-block-format-counts db))
         "Block format counts")
         "Block format counts")
 
 
     (is (= {:description 81, :updated-at 46, :tags 5, :logseq.macro-arguments 104
     (is (= {:description 81, :updated-at 46, :tags 5, :logseq.macro-arguments 104
@@ -161,7 +161,7 @@
   ;; only increase over time as the docs graph rarely has deletions
   ;; only increase over time as the docs graph rarely has deletions
   (testing "Counts"
   (testing "Counts"
     (is (= 303 (count files)) "Correct file count")
     (is (= 303 (count files)) "Correct file count")
-    (is (= 63733 (count (d/datoms db :eavt))) "Correct datoms count")
+    (is (= 64392 (count (d/datoms db :eavt))) "Correct datoms count")
 
 
     (is (= 5866
     (is (= 5866
            (ffirst
            (ffirst

+ 1 - 1
deps/graph-parser/test/logseq/graph_parser/cli_test.cljs

@@ -137,7 +137,7 @@
                      frontend-blocks)
                      frontend-blocks)
         _ (sqlite-db/upsert-blocks! db-name (bean/->js blocks))
         _ (sqlite-db/upsert-blocks! db-name (bean/->js blocks))
         conn (sqlite-cli/read-graph db-name)]
         conn (sqlite-cli/read-graph db-name)]
-    (ldb/create-default-pages! conn)
+    (ldb/create-default-pages! conn {:db-graph? true})
     @conn))
     @conn))
 
 
 (defn- datoms->entity-maps
 (defn- datoms->entity-maps

+ 3 - 2
scripts/src/logseq/tasks/db_graph/create_graph.cljs

@@ -38,7 +38,7 @@
   ;; Same order as frontend.db.conn/start!
   ;; Same order as frontend.db.conn/start!
   (let [conn (ldb/start-conn :create-default-pages? false)]
   (let [conn (ldb/start-conn :create-default-pages? false)]
     (persist-graph/add-listener conn db-name)
     (persist-graph/add-listener conn db-name)
-    (ldb/create-default-pages! conn)
+    (ldb/create-default-pages! conn {:db-graph? true})
     (setup-init-data conn)
     (setup-init-data conn)
     conn))
     conn))
 
 
@@ -182,7 +182,8 @@
                   {:db/id page-id
                   {:db/id page-id
                    :block/original-name (or (:block/original-name page) (string/capitalize (:block/name page)))
                    :block/original-name (or (:block/original-name page) (string/capitalize (:block/name page)))
                    :block/name (or (:block/name page) (sqlite-util/sanitize-page-name (:block/original-name page)))
                    :block/name (or (:block/name page) (sqlite-util/sanitize-page-name (:block/original-name page)))
-                   :block/journal? false}
+                   :block/journal? false
+                   :block/format :markdown}
                   (dissoc page :properties)
                   (dissoc page :properties)
                   (when (seq (:properties page))
                   (when (seq (:properties page))
                     {:block/properties (->block-properties-tx (:properties page) uuid-maps)
                     {:block/properties (->block-properties-tx (:properties page) uuid-maps)

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

@@ -84,13 +84,13 @@
 (defn start!
 (defn start!
   ([repo]
   ([repo]
    (start! repo {}))
    (start! repo {}))
-  ([repo {:keys [listen-handler]}]
+  ([repo {:keys [listen-handler db-graph?]}]
    (let [db-name (datascript-db repo)
    (let [db-name (datascript-db repo)
          db-conn (ldb/start-conn :schema (get-schema repo) :create-default-pages? false)]
          db-conn (ldb/start-conn :schema (get-schema repo) :create-default-pages? false)]
      (swap! conns assoc db-name db-conn)
      (swap! conns assoc db-name db-conn)
      (when listen-handler
      (when listen-handler
        (listen-handler repo))
        (listen-handler repo))
-     (ldb/create-default-pages! db-conn))))
+     (ldb/create-default-pages! db-conn {:db-graph? db-graph?}))))
 
 
 (defn destroy-all!
 (defn destroy-all!
   []
   []

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

@@ -179,7 +179,7 @@
         page-entity (db/entity [:block/name page-name])
         page-entity (db/entity [:block/name 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"} :block/format :markdown)))
         page-tx (when-not page-entity page)
         page-tx (when-not page-entity page)
         page-id [:block/uuid (:block/uuid page)]
         page-id [:block/uuid (:block/uuid page)]
         parent-id (db/new-block-id)
         parent-id (db/new-block-id)
@@ -213,7 +213,7 @@
         page-entity (db/entity [:block/name page-name])
         page-entity (db/entity [:block/name 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"} :block/format :markdown)))
         page-tx (when-not page-entity page)
         page-tx (when-not page-entity page)
         page-id [:block/uuid (:block/uuid page)]
         page-id [:block/uuid (:block/uuid page)]
         block-id (db/new-block-id)
         block-id (db/new-block-id)

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

@@ -365,7 +365,8 @@
 (defn start-repo-db-if-not-exists!
 (defn start-repo-db-if-not-exists!
   [repo]
   [repo]
   (state/set-current-repo! repo)
   (state/set-current-repo! repo)
-  (db/start-db-conn! repo {:listen-handler db-listener/listen-and-persist!}))
+  (db/start-db-conn! repo {:listen-handler db-listener/listen-and-persist!
+                           :db-graph? (config/db-based-graph? repo)}))
 
 
 (defn- setup-local-repo-if-not-exists-impl!
 (defn- setup-local-repo-if-not-exists-impl!
   []
   []

+ 2 - 1
src/main/frontend/handler/web/nfs.cljs

@@ -295,7 +295,8 @@
       (search/reset-indice! repo)
       (search/reset-indice! repo)
       (db/remove-conn! repo)
       (db/remove-conn! repo)
       (db/clear-query-state!)
       (db/clear-query-state!)
-      (db/start-db-conn! repo {:listen-handler db-listener/listen-and-persist!})
+      (db/start-db-conn! repo {:listen-handler db-listener/listen-and-persist!
+                               :db-graph? (config/db-based-graph? repo)})
       (reload-dir! repo {:re-index? true
       (reload-dir! repo {:re-index? true
                          :ok-handler ok-handler}))))
                          :ok-handler ok-handler}))))
 
 

+ 1 - 0
src/main/frontend/modules/outliner/core.cljs

@@ -168,6 +168,7 @@
                              (concat txs
                              (concat txs
                                      [(assoc page-m
                                      [(assoc page-m
                                              :block/tags (:block/tags m)
                                              :block/tags (:block/tags m)
+                                             :block/format :markdown
                                              :block/type "object")
                                              :block/type "object")
                                       {:db/id (:db/id block-entity)
                                       {:db/id (:db/id block-entity)
                                        :block/content ""
                                        :block/content ""