瀏覽代碼

fix: built in pages don't have client side timestamps

Tienson Qin 2 年之前
父節點
當前提交
b32d2caa2d
共有 2 個文件被更改,包括 19 次插入12 次删除
  1. 14 5
      deps/db/src/logseq/db.cljs
  2. 5 7
      src/main/frontend/db/restore.cljs

+ 14 - 5
deps/db/src/logseq/db.cljs

@@ -2,17 +2,26 @@
   "Main namespace for public db fns"
   (:require [logseq.db.default :as default-db]
             [logseq.db.schema :as db-schema]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [cljs-time.core :as t]
+            [cljs-time.coerce :as tc]))
 
 (defn create-default-pages!
   "Creates default pages if one of the default pages does not exist. This
    fn is idempotent"
   [db-conn]
   (when-not (d/entity @db-conn [:block/name "card"])
-    (d/transact! db-conn
-                 (concat
-                  [{:schema/version db-schema/version}]
-                  default-db/built-in-pages))))
+    (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)]
+      (d/transact! db-conn
+       (concat
+        [{:schema/version db-schema/version}]
+        built-in-pages-with-timestamp)))))
 
 (defn start-conn
   "Create datascript conn with schema and default data"

+ 5 - 7
src/main/frontend/db/restore.cljs

@@ -48,11 +48,9 @@
                                    (catch :default _e
                                      (js/console.warn "Invalid graph cache")
                                      (d/empty-db (db-conn/get-schema repo))))
-                    attached-db (d/db-with stored-db
-                                           default-db/built-in-pages) ;; TODO bug overriding uuids?
-                    db (if (old-schema? attached-db)
-                         (db-migrate/migrate attached-db)
-                         attached-db)]
+                    db (if (old-schema? stored-db)
+                         (db-migrate/migrate stored-db)
+                         stored-db)]
                 (db-conn/reset-conn! db-conn db)))]
     (d/transact! db-conn [{:schema/version db-schema/version}])))
 
@@ -74,9 +72,9 @@
                             (str "DB init! " (count all-datoms) " datoms")
                             (d/init-db all-datoms schema)))
         new-db (sqlite-restore/restore-other-data conn data uuid->db-id-map {:init-db-fn profiled-init-db})]
-    
+
     (reset! conn new-db)
-    
+
     (let [end (util/time-ms)]
       (println "[debug] load others from SQLite: " (int (- end start)) " ms."))