Skip to content

Commit

Permalink
fix: disable reactive queries in api
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Apr 12, 2023
1 parent d01b2e3 commit cb7e132
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@
[config id label]
(if-let [block-id (parse-uuid id)]
(let [db-id (:db/id (db/pull [:block/uuid block-id]))
block (when db-id (db/pull-block db-id))
block (when db-id (db/sub-block db-id))
block-type (keyword (get-in block [:block/properties :ls-type]))
hl-type (get-in block [:block/properties :hl-type])
repo (state/get-current-repo)
Expand Down Expand Up @@ -2753,7 +2753,7 @@
(first tree))
block)
block (if ref?
(merge block (db/pull-block (:db/id block)))
(merge block (db/sub-block (:db/id block)))
block)
{:block/keys [uuid children pre-block? top? refs level format content properties]} block
config (if navigated? (assoc config :id (str navigating-block)) config)
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/whiteboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
portal?]
:or {portal? true}}]
(let [page-entity (model/get-page page-name-or-uuid)
page (model/pull-block (:db/id page-entity))
page (model/sub-block (:db/id page-entity))
block-uuid (:block/uuid page-entity)
refs-count (count (:block/_refs page))]
(when (> refs-count 0)
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-properties
get-page-referenced-blocks get-page-referenced-blocks-full get-page-referenced-pages get-page-unlinked-references
get-all-pages get-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
journal-page? page-alias-set pull-block
journal-page? page-alias-set sub-block
set-file-last-modified-at! page-empty? page-exists? page-empty-or-dummy? get-alias-source-page
set-file-content! has-children? get-namespace-pages get-all-namespace-relation get-pages-by-name-partition
get-original-name]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
{:block/page [:db/id :block/name :block/original-name :block/journal-day]}
{:block/_parent ...}])

(defn pull-block
(defn sub-block
[id]
(when-let [repo (state/get-current-repo)]
(->
Expand Down
12 changes: 7 additions & 5 deletions src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
[frontend.db.model :as db-model]
[frontend.db.query-dsl :as query-dsl]
[frontend.db.utils :as db-utils]
[frontend.db.react :refer [sub-key-value]]
[frontend.db.query-react :as query-react]
[frontend.fs :as fs]
[frontend.handler.dnd :as editor-dnd-handler]
Expand Down Expand Up @@ -45,6 +44,8 @@
[frontend.handler.code :as code-handler]
[frontend.handler.search :as search-handler]))

;; Alert: this namespace shouldn't invoke any reactive queries

;; helpers
(defn ^:export install-plugin-hook
[pid hook ^js opts]
Expand Down Expand Up @@ -126,16 +127,16 @@

(def ^:export get_current_graph_recent
(fn []
(some->> (sub-key-value :recent/pages)
(some->> (db/get-key-value :recent/pages)
(remove string/blank?)
(filter string?)
(bean/->js))))

(def ^:export get_current_graph_templates
(fn []
(when-let [_repo (state/get-current-repo)]
(when (state/get-current-repo)
(some-> (db-model/get-all-templates)
(update-vals #(db-model/pull-block %))
(update-vals db/pull)
(sdk-utils/normalize-keyword-for-json)
(bean/->js)))))

Expand Down Expand Up @@ -873,7 +874,8 @@
(defn ^:export custom_query
[query-string]
(let [result (let [query (cljs.reader/read-string query-string)]
(db/custom-query {:query query}))]
(db/custom-query {:query query
:disable-reactive? true}))]
(bean/->js (sdk-utils/normalize-keyword-for-json (flatten @result)))))

(defn ^:export download_graph_db
Expand Down

0 comments on commit cb7e132

Please sign in to comment.