Skip to content

Commit

Permalink
fix: disable reactive query in api/q
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Apr 12, 2023
1 parent cb7e132 commit 86c5376
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/main/frontend/db/query_dsl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -587,22 +587,26 @@ Some bindings in this fn:

(defn query
"Runs a dsl query with query as a string. Primary use is from '{{query }}'"
[repo query-string]
(when (and (string? query-string) (not= "\"\"" query-string))
(let [{:keys [query rules sort-by blocks? sample]} (parse-query query-string)]
(when-let [query' (some-> query (query-wrapper {:blocks? blocks?}))]
(let [sort-by (or sort-by identity)
random-samples (if @sample
(fn [col]
(take @sample (shuffle col)))
identity)
transform-fn (comp sort-by random-samples)]
(query-react/react-query repo
{:query query'
:query-string query-string
:rules rules}
{:use-cache? false
:transform-fn transform-fn}))))))
([repo query-string]
(query repo query-string {}))
([repo query-string query-opts]
(when (and (string? query-string) (not= "\"\"" query-string))
(let [{:keys [query rules sort-by blocks? sample]} (parse-query query-string)]
(when-let [query' (some-> query (query-wrapper {:blocks? blocks?}))]
(let [sort-by (or sort-by identity)
random-samples (if @sample
(fn [col]
(take @sample (shuffle col)))
identity)
transform-fn (comp sort-by random-samples)]
(query-react/react-query repo
{:query query'
:query-string query-string
:rules rules}
(merge
{:use-cache? false
:transform-fn transform-fn}
query-opts))))))))

(defn custom-query
"Runs a dsl query with query as a seq. Primary use is from advanced query"
Expand Down
3 changes: 2 additions & 1 deletion src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@
(defn ^:export q
[query-string]
(when-let [repo (state/get-current-repo)]
(when-let [result (query-dsl/query repo query-string)]
(when-let [result (query-dsl/query repo query-string
{:disable-reactive? true})]
(bean/->js (sdk-utils/normalize-keyword-for-json (flatten @result))))))

(defn ^:export datascript_query
Expand Down

0 comments on commit 86c5376

Please sign in to comment.