mirror of https://github.com/logseq/logseq
fix: db import of aliases
Also ignore :filters for now so they don't make graphs invalid and add more tests for tags. Part of LOG-3176pull/11433/head
parent
33785dca66
commit
879e07b2f4
|
@ -29,7 +29,7 @@
|
|||
(def internal-property-ident
|
||||
[:or logseq-property-ident db-attribute-ident])
|
||||
|
||||
(defn- user-property?
|
||||
(defn user-property?
|
||||
"Determines if keyword/ident is a user property"
|
||||
[kw]
|
||||
(db-property/user-property-namespace? (namespace kw)))
|
||||
|
|
|
@ -285,13 +285,16 @@
|
|||
(def built-in-property-names
|
||||
"Set of all built-in property names as keywords. Using in-memory property
|
||||
names because these are legacy names already in a user's file graph"
|
||||
(->> built-in-property-name-to-idents keys set))
|
||||
(-> built-in-property-name-to-idents keys set
|
||||
;; :filters is not in built-in-properties because it maps to 2 new properties
|
||||
(conj :filters)))
|
||||
|
||||
(defn- update-built-in-property-values
|
||||
[props {:keys [ignored-properties all-idents]} {:block/keys [content name]}]
|
||||
(->> props
|
||||
(keep (fn [[prop val]]
|
||||
(if (= :icon prop)
|
||||
;; FIXME: Migrate :filters to :logseq.property.linked-references/* properties
|
||||
(if (#{:icon :filters} prop)
|
||||
(do (swap! ignored-properties
|
||||
conj
|
||||
{:property prop :value val :location (if name {:page name} {:block content})})
|
||||
|
@ -307,11 +310,6 @@
|
|||
[]))
|
||||
:query-sort-by
|
||||
(if (#{:page :block :created-at :updated-at} (keyword val)) (keyword val) (get-ident @all-idents (keyword val)))
|
||||
:filters
|
||||
(try (edn/read-string val)
|
||||
(catch :default e
|
||||
(js/console.error "Translating filters failed with:" e)
|
||||
{}))
|
||||
val)])))
|
||||
(into {})))
|
||||
|
||||
|
@ -634,14 +632,20 @@
|
|||
;; Order matters as properties are referenced in block
|
||||
(concat properties-tx deadline-properties-tx [block'])))
|
||||
|
||||
(defn- update-page-alias
|
||||
[m page-names-to-uuids]
|
||||
(update m :block/alias (fn [aliases]
|
||||
(map #(vector :block/uuid (get-page-uuid page-names-to-uuids (:block/name %)))
|
||||
aliases))))
|
||||
|
||||
(defn- build-new-page
|
||||
[m db tag-classes page-names-to-uuids]
|
||||
(-> m
|
||||
;; Fix pages missing :block/original-name. Shouldn't happen
|
||||
((fn [m']
|
||||
(if-not (:block/original-name m')
|
||||
(assoc m' :block/original-name (:block/name m'))
|
||||
m')))
|
||||
(-> (cond-> m
|
||||
;; Fix pages missing :block/original-name. Shouldn't happen
|
||||
(not (:block/original-name m))
|
||||
(assoc :block/original-name (:block/name m))
|
||||
(seq (:block/alias m))
|
||||
(update-page-alias page-names-to-uuids))
|
||||
add-missing-timestamps
|
||||
;; TODO: org-mode content needs to be handled
|
||||
(assoc :block/format :markdown)
|
||||
|
@ -681,6 +685,8 @@
|
|||
ignored-attrs)}))
|
||||
(when (seq block-changes)
|
||||
(cond-> (merge block-changes {:block/uuid page-uuid})
|
||||
(seq (:block/alias m))
|
||||
(update-page-alias page-names-to-uuids)
|
||||
(:block/tags m)
|
||||
(update-page-tags @conn tag-classes page-names-to-uuids))))
|
||||
(build-new-page m @conn tag-classes page-names-to-uuids)))
|
||||
|
|
|
@ -148,12 +148,12 @@
|
|||
(is (= 16 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
|
||||
|
||||
;; Don't count pages like url.md that have properties but no content
|
||||
(is (= 4
|
||||
(is (= 5
|
||||
(count (->> (d/q '[:find [(pull ?b [:block/original-name :block/type]) ...]
|
||||
:where [?b :block/original-name] [_ :block/page ?b]] @conn)
|
||||
(filter #(= ["page"] (:block/type %))))))
|
||||
"Correct number of pages with block content")
|
||||
(is (= 0 (count @(:ignored-properties import-state))) "No ignored properties")
|
||||
(is (= 1 (count @(:ignored-properties import-state))) ":filters should be the only ignored property")
|
||||
(is (= 1 (count @assets))))
|
||||
|
||||
(testing "logseq files"
|
||||
|
@ -172,7 +172,7 @@
|
|||
set))))
|
||||
|
||||
(testing "user properties"
|
||||
(is (= 16
|
||||
(is (= 17
|
||||
(->> @conn
|
||||
(d/q '[:find [(pull ?b [:db/ident]) ...]
|
||||
:where [?b :block/type "property"]])
|
||||
|
@ -259,6 +259,9 @@
|
|||
(readable-properties @conn (find-block-by-content @conn "list one")))
|
||||
"numered block has correct property")
|
||||
|
||||
(is (= #{"gpt"}
|
||||
(:block/alias (readable-properties @conn (find-page-by-name @conn "chat-gpt")))))
|
||||
|
||||
(is (= {:logseq.property/query-sort-by :user.property/prop-num
|
||||
:logseq.property/query-properties [:block :page :user.property/prop-string :user.property/prop-num]
|
||||
:logseq.property/query-table true}
|
||||
|
@ -333,7 +336,10 @@
|
|||
|
||||
(is (= {:logseq.property/page-tags #{"Movie"}}
|
||||
(readable-properties @conn tagged-page))
|
||||
"tagged page has tags imported as page-tags property by default")))))
|
||||
"tagged page has existing page imported as a tag to page-tags")
|
||||
(is (= #{"LargeLanguageModel" "fun" "ai"}
|
||||
(:logseq.property/page-tags (readable-properties @conn (find-page-by-name @conn "chat-gpt"))))
|
||||
"tagged page has new page and other pages marked with '#' and '[[]]` imported as tags to page-tags")))))
|
||||
|
||||
(deftest-async export-file-with-tag-classes-option
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
parent:: [[CreativeWork]]
|
|
@ -0,0 +1,6 @@
|
|||
filters:: {"contents" true}
|
||||
type:: [[LargeLanguageModel]]
|
||||
tags:: ai, #fun, [[LargeLanguageModel]]
|
||||
alias:: gpt
|
||||
|
||||
- some text
|
Loading…
Reference in New Issue