mirror of https://github.com/logseq/logseq
fix: wrong usage of :frontend.db.react/refs
Previously, `[:frontend.db.react/refs id]` is used for three places: 1. get-page-referenced-blocks 2. get-block-referenced-blocks 3. get-block-references-count The cached query atom will be shared between those three functions, the problem is that both queries in `get-page-referenced-blocks` and `get-block-referenced-blocks` return data of different formats, which can result in crashes in some situations (e.g. PR #8423). This commit removed `get-block-references-count` and use `model/pull-block` and `(count (:block/_refs block))` instead. We also need to make sure the `id` in `[:frontend.db.react/refs id]` will be different for `get-page-referenced-blocks` and `get-block-referenced-blocks`. We can probably get rid of `get-page-referenced-blocks` once we refactored both linked references and filters for pages.pull/8671/head
parent
5a2884038b
commit
0e365508be
|
@ -122,8 +122,9 @@
|
||||||
portal?]
|
portal?]
|
||||||
:or {portal? true}}]
|
:or {portal? true}}]
|
||||||
(let [page-entity (model/get-page page-name-or-uuid)
|
(let [page-entity (model/get-page page-name-or-uuid)
|
||||||
|
page (model/pull-block (:db/id page-entity))
|
||||||
block-uuid (:block/uuid page-entity)
|
block-uuid (:block/uuid page-entity)
|
||||||
refs-count (model/get-block-references-count block-uuid)]
|
refs-count (count (:block/_refs page))]
|
||||||
(when (> refs-count 0)
|
(when (> refs-count 0)
|
||||||
(dropdown-menu {:classname classname
|
(dropdown-menu {:classname classname
|
||||||
:label (fn [open?]
|
:label (fn [open?]
|
||||||
|
|
|
@ -1336,24 +1336,6 @@ independent of format as format specific heading characters are stripped"
|
||||||
(sort-by-left-recursive))]
|
(sort-by-left-recursive))]
|
||||||
(db-utils/group-by-page query-result))))))
|
(db-utils/group-by-page query-result))))))
|
||||||
|
|
||||||
(defn get-block-references-count
|
|
||||||
[block-uuid]
|
|
||||||
(when-let [repo (state/get-current-repo)]
|
|
||||||
(when (conn/get-db repo)
|
|
||||||
(let [block (db-utils/entity [:block/uuid block-uuid])
|
|
||||||
query-result (->> (react/q repo [:frontend.db.react/refs
|
|
||||||
(:db/id block)]
|
|
||||||
{}
|
|
||||||
'[:find [(pull ?ref-block ?block-attrs) ...]
|
|
||||||
:in $ ?block-uuid ?block-attrs
|
|
||||||
:where
|
|
||||||
[?block :block/uuid ?block-uuid]
|
|
||||||
[?ref-block :block/refs ?block]]
|
|
||||||
block-uuid
|
|
||||||
block-attrs)
|
|
||||||
react)]
|
|
||||||
(count query-result)))))
|
|
||||||
|
|
||||||
(defn journal-page?
|
(defn journal-page?
|
||||||
"sanitized page-name only"
|
"sanitized page-name only"
|
||||||
[page-name]
|
[page-name]
|
||||||
|
|
|
@ -257,9 +257,11 @@
|
||||||
(:db/id (:block/page block)))
|
(:db/id (:block/page block)))
|
||||||
blocks [[::block (:db/id block)]]
|
blocks [[::block (:db/id block)]]
|
||||||
path-refs (:block/path-refs block)
|
path-refs (:block/path-refs block)
|
||||||
path-refs' (keep (fn [ref]
|
path-refs' (->> (keep (fn [ref]
|
||||||
(when-not (= (:db/id ref) page-id)
|
(when-not (= (:db/id ref) page-id)
|
||||||
[::refs (:db/id ref)])) path-refs)
|
[[::refs (:db/id ref)]
|
||||||
|
[::block (:db/id ref)]])) path-refs)
|
||||||
|
(apply concat))
|
||||||
page-blocks (when page-id
|
page-blocks (when page-id
|
||||||
[[::page-blocks page-id]])]
|
[[::page-blocks page-id]])]
|
||||||
(concat blocks page-blocks path-refs')))
|
(concat blocks page-blocks path-refs')))
|
||||||
|
@ -267,7 +269,8 @@
|
||||||
|
|
||||||
(mapcat
|
(mapcat
|
||||||
(fn [ref]
|
(fn [ref]
|
||||||
[[::refs ref]])
|
[[::refs ref]
|
||||||
|
[::block ref]])
|
||||||
refs)
|
refs)
|
||||||
|
|
||||||
(when-let [current-page-id (:db/id (get-current-page))]
|
(when-let [current-page-id (:db/id (get-current-page))]
|
||||||
|
|
Loading…
Reference in New Issue