mirror of https://github.com/logseq/logseq
fix: property simple queries by name
Maintains backwards compatibility for property filter queries which fixes imported and handwritten property queries. Extended sqlite.build and test-helper capabilities in order to test this. Fixes LOG-3231pull/11531/head
parent
65fca295c4
commit
be54ab98e6
|
@ -156,7 +156,8 @@
|
||||||
(let [new-block
|
(let [new-block
|
||||||
(merge (sqlite-util/build-new-property (get-ident all-idents prop-name)
|
(merge (sqlite-util/build-new-property (get-ident all-idents prop-name)
|
||||||
(:block/schema prop-m)
|
(:block/schema prop-m)
|
||||||
{:block-uuid (:block/uuid prop-m)})
|
{:block-uuid (:block/uuid prop-m)
|
||||||
|
:title (:block/title prop-m)})
|
||||||
{:db/id (or (property-db-ids prop-name)
|
{:db/id (or (property-db-ids prop-name)
|
||||||
(throw (ex-info "No :db/id for property" {:property prop-name})))})
|
(throw (ex-info "No :db/id for property" {:property prop-name})))})
|
||||||
pvalue-tx-m (->property-value-tx-m new-block (:build/properties prop-m) properties all-idents)]
|
pvalue-tx-m (->property-value-tx-m new-block (:build/properties prop-m) properties all-idents)]
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
[frontend.util.text :as text-util]
|
[frontend.util.text :as text-util]
|
||||||
[frontend.util :as util]
|
[frontend.util :as util]
|
||||||
[frontend.config :as config]
|
[frontend.config :as config]
|
||||||
[logseq.db.frontend.property :as db-property]
|
|
||||||
[frontend.state :as state]))
|
[frontend.state :as state]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +283,14 @@
|
||||||
[property-name]
|
[property-name]
|
||||||
(if (qualified-keyword? property-name)
|
(if (qualified-keyword? property-name)
|
||||||
property-name
|
property-name
|
||||||
(keyword db-property/default-user-namespace (name property-name))))
|
(or (some->> (name property-name)
|
||||||
|
(db-utils/q '[:find [(pull ?b [:db/ident]) ...]
|
||||||
|
:in $ ?title
|
||||||
|
:where [?b :block/type "property"] [?b :block/title ?title]])
|
||||||
|
first
|
||||||
|
:db/ident)
|
||||||
|
;; Don't return nil as that incorrectly matches all properties
|
||||||
|
::no-property-found)))
|
||||||
|
|
||||||
(defn- build-property-two-arg
|
(defn- build-property-two-arg
|
||||||
[e {:keys [db-graph?]}]
|
[e {:keys [db-graph?]}]
|
||||||
|
|
|
@ -150,22 +150,30 @@ prop-d:: [[nada]]"}])
|
||||||
(test-helper/with-config {}
|
(test-helper/with-config {}
|
||||||
(block-property-queries-test))))
|
(block-property-queries-test))))
|
||||||
|
|
||||||
|
|
||||||
(when js/process.env.DB_GRAPH
|
(when js/process.env.DB_GRAPH
|
||||||
(deftest db-only-block-property-queries
|
(deftest db-only-block-property-queries
|
||||||
(load-test-files-for-db-graph
|
(load-test-files-for-db-graph
|
||||||
|
{:properties
|
||||||
|
{:zzz {:block/schema {:type :default}
|
||||||
|
:block/title "zzz name!"}}
|
||||||
|
:pages-and-blocks
|
||||||
[{:page {:block/title "page1"}
|
[{:page {:block/title "page1"}
|
||||||
:blocks [{:block/title "b1"
|
:blocks [{:block/title "b1"
|
||||||
:build/properties {:Foo "bar"}}
|
:build/properties {:Foo "bar"}}
|
||||||
{:block/title "b2"
|
{:block/title "b2"
|
||||||
:build/properties {:foo "bar"}}]}])
|
:build/properties {:foo "bar"}}
|
||||||
|
{:block/title "b3"
|
||||||
|
:build/properties {:zzz "bar"}}]}]})
|
||||||
|
|
||||||
(is (= ["b1"]
|
(is (= ["b1"]
|
||||||
(map :block/title (dsl-query "(property Foo)")))
|
(map :block/title (dsl-query "(property Foo)")))
|
||||||
"filter is case sensitive")
|
"filter is case sensitive")
|
||||||
(is (= ["b2"]
|
(is (= ["b2"]
|
||||||
(map :block/title (dsl-query "(property :user.property/foo)")))
|
(map :block/title (dsl-query "(property :user.property/foo)")))
|
||||||
"filter can handle qualified keyword properties")))
|
"filter can handle qualified keyword properties")
|
||||||
|
(is (= ["b3"]
|
||||||
|
(map :block/title (dsl-query "(property \"zzz name!\")")))
|
||||||
|
"filter can handle property name")))
|
||||||
|
|
||||||
(deftest block-property-query-performance
|
(deftest block-property-query-performance
|
||||||
(let [pages (->> (repeat 10 {:tags ["tag1" "tag2"]})
|
(let [pages (->> (repeat 10 {:tags ["tag1" "tag2"]})
|
||||||
|
|
|
@ -153,8 +153,11 @@
|
||||||
(defn load-test-files-for-db-graph
|
(defn load-test-files-for-db-graph
|
||||||
[options*]
|
[options*]
|
||||||
(let [;; Builds options from markdown :file/content unless given explicit build-blocks config
|
(let [;; Builds options from markdown :file/content unless given explicit build-blocks config
|
||||||
options (if (:page (first options*))
|
options (cond (:page (first options*))
|
||||||
{:pages-and-blocks options* :auto-create-ontology? true}
|
{:pages-and-blocks options* :auto-create-ontology? true}
|
||||||
|
(:pages-and-blocks options*)
|
||||||
|
(assoc options* :auto-create-ontology? true)
|
||||||
|
:else
|
||||||
(build-blocks-tx-options options*))
|
(build-blocks-tx-options options*))
|
||||||
{:keys [init-tx block-props-tx]} (sqlite-build/build-blocks-tx options)]
|
{:keys [init-tx block-props-tx]} (sqlite-build/build-blocks-tx options)]
|
||||||
(db/transact! test-db init-tx)
|
(db/transact! test-db init-tx)
|
||||||
|
|
Loading…
Reference in New Issue