Browse Source

fix: adding timestamps to imports shouldn't change updated-at

Gabriel Horner 1 năm trước cách đây
mục cha
commit
a2bb7e4479
1 tập tin đã thay đổi với 15 bổ sung5 xóa
  1. 15 5
      deps/graph-parser/src/logseq/graph_parser.cljs

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

@@ -8,8 +8,7 @@
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.date-time-util :as date-time-util]
             [logseq.graph-parser.extract :as extract]
-            [logseq.graph-parser.util :as gp-util]
-            [logseq.db.sqlite.util :as sqlite-util]))
+            [logseq.graph-parser.util :as gp-util]))
 
 (defn- retract-blocks-tx
   [blocks retain-uuids]
@@ -136,13 +135,24 @@ Options available:
   [db property-name]
   (:block/uuid (d/entity db [:block/name (gp-util/page-name-sanity-lc (name property-name))])))
 
+(defn add-missing-timestamps
+  "Add updated-at or created-at timestamps if they doesn't exist"
+  [block]
+  (let [updated-at (date-time-util/time-ms)
+        block (cond-> block
+                (nil? (:block/updated-at block))
+                (assoc :block/updated-at updated-at)
+                (nil? (:block/created-at block))
+                (assoc :block/created-at updated-at))]
+    block))
+
 (defn- update-block-with-invalid-tags
   [block]
   (if (seq (:block/tags block))
     (update block :block/tags
             (fn [tags]
               (mapv #(-> %
-                         sqlite-util/block-with-timestamps
+                         add-missing-timestamps
                          (merge {:block/journal? false
                                  :block/format :markdown
                                  :block/uuid (d/squuid)}))
@@ -186,7 +196,7 @@ Options available:
                      (fn [refs]
                        (mapv #(assoc % :block/format :markdown) refs)))
              block')))
-        sqlite-util/block-with-timestamps
+        add-missing-timestamps
         ;; FIXME: Remove when properties are supported
         (assoc :block/properties {})
         ;; TODO: org-mode content needs to be handled
@@ -238,7 +248,7 @@ Options available:
                                  (if-not (:block/original-name m)
                                    (assoc m :block/original-name (:block/name m))
                                    m)))
-                              sqlite-util/block-with-timestamps
+                              add-missing-timestamps
                               ;; TODO: org-mode content needs to be handled
                               (assoc :block/format :markdown)
                               (dissoc :block/properties-text-values :block/properties-order :block/invalid-properties