Przeglądaj źródła

fix: update ds sqlite persistance to match latest frontend

also removed unused util fns
Gabriel Horner 2 lat temu
rodzic
commit
fb3e8e8d8a

+ 0 - 36
deps/db/src/logseq/db/sqlite/util.cljs

@@ -4,29 +4,6 @@
             [cljs-time.core :as t]
             [clojure.string :as string]))
 
-(defn- type-of-block
-  "
-  TODO: use :block/type
-  FIXME: 4 isn't used. Delete it?
-  | value | meaning                                        |
-  |-------+------------------------------------------------|
-  |     1 | normal block                                   |
-  |     2 | page block                                     |
-  |     3 | init data, (config.edn, custom.js, custom.css) |
-  |     4 | db schema                                      |
-  |     5 | unknown type                                   |
-  |     6 | property block                                 |
-  |     7 | macro                                          |
-  "
-  [block]
-  (cond
-    (:block/page block) 1
-    (some #{:file/content :schema/version :db/type} (keys block)) 3
-    (contains? (:block/type block) "property") 6
-    (:block/name block) 2
-    (contains? (set (:block/type block)) "macro") 7
-    :else 5))
-
 (defonce db-version-prefix "logseq_db_")
 
 (defn time-ms
@@ -34,19 +11,6 @@
   []
   (tc/to-long (t/now)))
 
-(defn ds->sqlite-block
-  "Convert a datascript block to a sqlite map in preparation for a sqlite-db fn"
-  [b]
-  {:uuid (str (:block/uuid b))
-   :type (type-of-block b)
-   :page_uuid (str (:page_uuid b))
-   :page_journal_day (:block/journal-day b)
-   :name (or (:file/path b) (:block/name b))
-   :content (or (:file/content b) (:block/content b))
-   :datoms (:datoms b)
-   :created_at (or (:block/created-at b) (time-ms))
-   :updated_at (or (:block/updated-at b) (time-ms))})
-
 (defn block-with-timestamps
   "Adds updated-at timestamp and created-at if it doesn't exist"
   [block]

+ 1 - 1
deps/db/test/logseq/db/sqlite/restore_test.cljs

@@ -43,7 +43,7 @@
           _ (sqlite-db/transact! "test-db" frontend-blocks {})
           conn (-> (sqlite-db/get-initial-data "test-db")
                    sqlite-restore/restore-initial-data)]
-      (is (= (map #(dissoc % :page_uuid) frontend-blocks)
+      (is (= frontend-blocks
              (->> (d/q '[:find (pull ?b [*])
                          :where [?b :block/created-at]]
                        @conn)

+ 8 - 18
deps/outliner/src/logseq/outliner/cli/persist_graph.cljs

@@ -5,34 +5,24 @@
    * Deleted blocks don't update effected :block/tx-id"
   (:require [datascript.core :as d]
             [logseq.db.sqlite.db :as sqlite-db]
-            [logseq.db.sqlite.util :as sqlite-util]
-            [cljs-bean.core :as bean]
             [logseq.outliner.datascript-report :as ds-report]
             [logseq.outliner.pipeline :as outliner-pipeline]))
 
 (defn- invoke-hooks
   "Modified copy of frontend.modules.outliner.pipeline/invoke-hooks that doesn't
   handle :block/tx-id"
-  [conn {:keys [db-after] :as tx-report}]
+  [conn tx-report]
   (when (not (get-in tx-report [:tx-meta :replace?]))
     (let [{:keys [blocks]} (ds-report/get-blocks-and-pages tx-report)
-          block-path-refs-tx (outliner-pipeline/compute-block-path-refs-tx tx-report blocks)
-          db-after' (if (seq block-path-refs-tx)
-                      (:db-after (d/transact! conn block-path-refs-tx {:replace? true}))
-                      db-after)
-          deleted-block-uuids (set (outliner-pipeline/filter-deleted-blocks (:tx-data tx-report)))
-          upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids db-after')]
-      {:blocks upsert-blocks
-       :deleted-block-uuids deleted-block-uuids})))
+          block-path-refs-tx (outliner-pipeline/compute-block-path-refs-tx tx-report blocks)]
+      (d/transact! conn block-path-refs-tx {:replace? true})
+      ;; frontend also passes original tx-report
+      tx-report)))
 
 (defn- update-sqlite-db
-  "Modified copy of :db-transact-data defmethod in electron.handler"
-  [db-name {:keys [blocks deleted-block-uuids]}]
-  (when (seq deleted-block-uuids)
-    (sqlite-db/delete-blocks! db-name deleted-block-uuids))
-  (when (seq blocks)
-    (let [blocks' (mapv sqlite-util/ds->sqlite-block blocks)]
-      (sqlite-db/upsert-blocks! db-name (bean/->js blocks')))))
+  "Same as :db-transact-data defmethod in electron.handler"
+  [db-name tx-report]
+  (sqlite-db/transact! db-name (:tx-data tx-report) (:tx-meta tx-report)))
 
 (defn add-listener
   "Adds a listener to the datascript connection to persist changes to the given