Browse Source

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

Tienson Qin 2 years ago
parent
commit
b32d2caa2d
2 changed files with 19 additions and 12 deletions
  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"
   "Main namespace for public db fns"
   (:require [logseq.db.default :as default-db]
   (:require [logseq.db.default :as default-db]
             [logseq.db.schema :as db-schema]
             [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!
 (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]
   (when-not (d/entity @db-conn [:block/name "card"])
   (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
 (defn start-conn
   "Create datascript conn with schema and default data"
   "Create datascript conn with schema and default data"

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

@@ -48,11 +48,9 @@
                                    (catch :default _e
                                    (catch :default _e
                                      (js/console.warn "Invalid graph cache")
                                      (js/console.warn "Invalid graph cache")
                                      (d/empty-db (db-conn/get-schema repo))))
                                      (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)))]
                 (db-conn/reset-conn! db-conn db)))]
     (d/transact! db-conn [{:schema/version db-schema/version}])))
     (d/transact! db-conn [{:schema/version db-schema/version}])))
 
 
@@ -74,9 +72,9 @@
                             (str "DB init! " (count all-datoms) " datoms")
                             (str "DB init! " (count all-datoms) " datoms")
                             (d/init-db all-datoms schema)))
                             (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})]
         new-db (sqlite-restore/restore-other-data conn data uuid->db-id-map {:init-db-fn profiled-init-db})]
-    
+
     (reset! conn new-db)
     (reset! conn new-db)
-    
+
     (let [end (util/time-ms)]
     (let [end (util/time-ms)]
       (println "[debug] load others from SQLite: " (int (- end start)) " ms."))
       (println "[debug] load others from SQLite: " (int (- end start)) " ms."))