|
|
@@ -731,7 +731,7 @@
|
|
|
|
|
|
(defn- handle-page-properties
|
|
|
"Adds page properties including special handling for :logseq.property/parent"
|
|
|
- [{:block/keys [properties] :as block*} db {:keys [page-names-to-uuids]} refs
|
|
|
+ [{:block/keys [properties] :as block*} db {:keys [page-names-to-uuids classes-tx]} refs
|
|
|
{:keys [user-options log-fn import-state] :as options}]
|
|
|
(let [{:keys [block properties-tx]} (handle-page-and-block-properties block* db page-names-to-uuids refs options)
|
|
|
block'
|
|
|
@@ -740,18 +740,18 @@
|
|
|
distinct
|
|
|
seq)]
|
|
|
(let [_ (swap! (:classes-from-property-parents import-state) conj (:block/title block*))
|
|
|
- ;; TODO: Mv new classes from these find-or-create-class to :classes-tx as they are the only ones
|
|
|
- ;; that aren't conrolled by :classes-tx
|
|
|
class-m (find-or-create-class db ((some-fn ::original-title :block/title) block) (:all-idents import-state) block)
|
|
|
class-m' (-> block
|
|
|
(merge class-m)
|
|
|
(assoc :logseq.property/parent
|
|
|
(let [new-class (first parent-classes-from-properties)
|
|
|
- class-m (find-or-create-class db new-class (:all-idents import-state))]
|
|
|
+ class-m (find-or-create-class db new-class (:all-idents import-state))
|
|
|
+ class-m' (merge class-m
|
|
|
+ {:block/uuid (find-or-gen-class-uuid page-names-to-uuids (common-util/page-name-sanity-lc new-class) (:db/ident class-m))})]
|
|
|
(when (> (count parent-classes-from-properties) 1)
|
|
|
(log-fn :skipped-parent-classes "Only one parent class is allowed so skipped ones after the first one" :classes parent-classes-from-properties))
|
|
|
- (merge class-m
|
|
|
- {:block/uuid (find-or-gen-class-uuid page-names-to-uuids (common-util/page-name-sanity-lc new-class) (:db/ident class-m))}))))]
|
|
|
+ (when (:new-class? (meta class-m)) (swap! classes-tx conj class-m'))
|
|
|
+ [:block/uuid (:block/uuid class-m')])))]
|
|
|
class-m')
|
|
|
block)
|
|
|
block'' (replace-namespace-with-parent block' page-names-to-uuids)]
|
|
|
@@ -1267,7 +1267,7 @@
|
|
|
(defn- clean-extra-invalid-tags
|
|
|
"If a page/class tx is an existing property or a new or existing class, ensure that
|
|
|
it only has one tag by removing :logseq.class/Page from its tx"
|
|
|
- [db pages-tx' classes-tx]
|
|
|
+ [db pages-tx' classes-tx existing-pages]
|
|
|
;; TODO: Improve perf if we tracked all created classes in atom
|
|
|
(let [existing-classes (->> (d/datoms db :avet :block/tags :logseq.class/Tag)
|
|
|
(map #(d/entity db (:e %)))
|
|
|
@@ -1278,7 +1278,13 @@
|
|
|
existing-properties (->> (d/datoms db :avet :block/tags :logseq.class/Property)
|
|
|
(map #(d/entity db (:e %)))
|
|
|
(map :block/uuid)
|
|
|
- set)]
|
|
|
+ set)
|
|
|
+ existing-pages' (set/map-invert existing-pages)
|
|
|
+ retract-page-tag-from-existing-pages
|
|
|
+ (->> pages-tx'
|
|
|
+ ;; Existing pages that have converted to property or class
|
|
|
+ (filter #(and (:db/ident %) (get existing-pages' (:block/uuid %))))
|
|
|
+ (mapv #(vector :db/retract [:block/uuid (:block/uuid %)] :block/tags :logseq.class/Page)))]
|
|
|
{:pages-tx
|
|
|
(mapv (fn [page]
|
|
|
(if (or (contains? classes (:block/uuid page))
|
|
|
@@ -1286,9 +1292,10 @@
|
|
|
(update page :block/tags (fn [tags] (vec (remove #(= % :logseq.class/Page) tags))))
|
|
|
page))
|
|
|
pages-tx')
|
|
|
- :retract-page-tag-from-classes-tx
|
|
|
- (mapv #(vector :db/retract [:block/uuid (:block/uuid %)] :block/tags :logseq.class/Page)
|
|
|
- classes-tx)}))
|
|
|
+ :retract-page-tags-tx
|
|
|
+ (into (mapv #(vector :db/retract [:block/uuid (:block/uuid %)] :block/tags :logseq.class/Page)
|
|
|
+ classes-tx)
|
|
|
+ retract-page-tag-from-existing-pages)}))
|
|
|
|
|
|
(defn add-file-to-db-graph
|
|
|
"Parse file and save parsed data to the given db graph. Options available:
|
|
|
@@ -1331,8 +1338,8 @@
|
|
|
main-props-tx-report (d/transact! conn property-pages-tx {::new-graph? true})
|
|
|
|
|
|
classes-tx @(:classes-tx tx-options)
|
|
|
- {:keys [retract-page-tag-from-classes-tx] pages-tx'' :pages-tx} (clean-extra-invalid-tags @conn pages-tx' classes-tx)
|
|
|
- classes-tx' (concat classes-tx retract-page-tag-from-classes-tx)
|
|
|
+ {:keys [retract-page-tags-tx] pages-tx'' :pages-tx} (clean-extra-invalid-tags @conn pages-tx' classes-tx existing-pages)
|
|
|
+ classes-tx' (concat classes-tx retract-page-tags-tx)
|
|
|
;; Build indices
|
|
|
pages-index (->> (map #(select-keys % [:block/uuid]) pages-tx'')
|
|
|
(concat (map #(select-keys % [:block/uuid]) classes-tx))
|