mirror of
https://github.com/logseq/logseq.git
synced 2026-05-04 02:46:45 +00:00
Fix: broken linked references (#6105)
* enhance: clicking the refresh button if a query is slow * fix: skip running slow queries if there's no need to refresh * fix: linked reference filtering does not work on TASK items close #1669 * fix: each block should have its own page as a reference when query page references * fix: references * fix: non consecutive blocks in query result and filtered linked references * simplify filters logic * fix: ref numbers * Save both :block/refs and :block/path-refs for different usage * fix: block refs * enhance: move scheduled and deadlines to its own ns * linked references performance tweaks * mouse hover filters icon to expand the collapsed linked refs * perf: react/refresh! once instead twice * enhance: compute flashcards every hour instead of every 5s * feat: macros as blocks * feat: flashcards list * fix: refed pages count * fix: can't select in linked references * fix: block editing on linked refs * perf: editing in linked references * enhance: update srs cards number when clicking flashcards * Add a test for the case fixed in #6100 * Address feedbacks from Gabriel * fix: Block Ref Indicator is missing from the references-blocks class close #5375 * fix: referenced pages * fix: page refs * fix: Using filters pushed the title property to the second block close #5845 Co-authored-by: Gabriel Horner <gabriel@logseq.com>
This commit is contained in:
@@ -21,58 +21,6 @@
|
||||
[repo page-id]
|
||||
(>= (db/get-page-blocks-count repo page-id) db-model/initial-blocks-length))
|
||||
|
||||
(defn get-block-refs-with-children
|
||||
[block]
|
||||
(->>
|
||||
(tree-seq :block/refs
|
||||
:block/children
|
||||
block)
|
||||
(mapcat :block/refs)
|
||||
(distinct)))
|
||||
|
||||
(defn filter-blocks
|
||||
[repo ref-blocks filters group-by-page?]
|
||||
(let [ref-pages-ids (->> (if group-by-page?
|
||||
(mapcat last ref-blocks)
|
||||
ref-blocks)
|
||||
(mapcat (fn [b] (get-block-refs-with-children b)))
|
||||
(concat (when group-by-page? (map first ref-blocks)))
|
||||
(distinct)
|
||||
(map :db/id)
|
||||
(remove nil?))
|
||||
ref-pages (db/pull-many repo '[:db/id :block/name] ref-pages-ids)
|
||||
ref-pages (zipmap (map :block/name ref-pages) (map :db/id ref-pages))
|
||||
exclude-ids (->> (map (fn [page] (get ref-pages page)) (get filters false))
|
||||
(remove nil?)
|
||||
(set))
|
||||
include-ids (->> (map (fn [page] (get ref-pages page)) (get filters true))
|
||||
(remove nil?)
|
||||
(set))]
|
||||
(if (empty? filters)
|
||||
ref-blocks
|
||||
(let [filter-f (fn [ref-blocks]
|
||||
(cond->> ref-blocks
|
||||
(seq exclude-ids)
|
||||
(remove (fn [block]
|
||||
(let [ids (set (concat (map :db/id (get-block-refs-with-children block))
|
||||
[(:db/id (:block/page block))]))]
|
||||
(seq (set/intersection exclude-ids ids)))))
|
||||
|
||||
(seq include-ids)
|
||||
(remove (fn [block]
|
||||
(let [page-block-id (:db/id (:block/page block))
|
||||
ids (set (map :db/id (get-block-refs-with-children block)))]
|
||||
(if (and (contains? include-ids page-block-id)
|
||||
(= 1 (count include-ids)))
|
||||
(not= page-block-id (first include-ids))
|
||||
(empty? (set/intersection include-ids (set (conj ids page-block-id))))))))))]
|
||||
(if group-by-page?
|
||||
(->> (map (fn [[p ref-blocks]]
|
||||
[p (filter-f ref-blocks)]) ref-blocks)
|
||||
(remove #(empty? (second %))))
|
||||
(->> (filter-f ref-blocks)
|
||||
(remove nil?)))))))
|
||||
|
||||
;; TODO: reduced version
|
||||
(defn- walk-block
|
||||
[block check? transform]
|
||||
@@ -138,8 +86,8 @@
|
||||
(defn indent-outdent-block!
|
||||
[block direction]
|
||||
(outliner-tx/transact!
|
||||
{:outliner-op :move-blocks}
|
||||
(outliner-core/indent-outdent-blocks! [block] (= direction :right))))
|
||||
{:outliner-op :move-blocks}
|
||||
(outliner-core/indent-outdent-blocks! [block] (= direction :right))))
|
||||
|
||||
(defn select-block!
|
||||
[block-uuid]
|
||||
@@ -298,3 +246,43 @@
|
||||
(reset! *show-left-menu? false)
|
||||
(reset! *show-right-menu? false)
|
||||
(reset! *swipe nil))
|
||||
|
||||
(defn get-blocks-refed-pages
|
||||
[repo page-entity]
|
||||
(let [pages (db-model/page-alias-set repo (:block/name page-entity))
|
||||
refs (->> pages
|
||||
(mapcat (fn [id] (:block/_path-refs (db/entity id))))
|
||||
(mapcat (fn [b] (conj (:block/path-refs b) (:block/page b))))
|
||||
(remove (fn [r] (= (:db/id page-entity) (:db/id r)))))]
|
||||
(keep (fn [ref]
|
||||
(when (:block/name ref)
|
||||
{:db/id (:db/id ref)
|
||||
:block/name (:block/name ref)
|
||||
:block/original-name (:block/original-name ref)})) refs)))
|
||||
|
||||
(defn- filter-blocks
|
||||
[ref-blocks filters ref-pages]
|
||||
(let [ref-pages (distinct ref-pages)]
|
||||
(if (empty? filters)
|
||||
ref-blocks
|
||||
(let [ref-pages (zipmap (map :block/name ref-pages) (map :db/id ref-pages))
|
||||
exclude-ids (->> (keep (fn [page] (get ref-pages page)) (get filters false))
|
||||
(set))
|
||||
include-ids (->> (keep (fn [page] (get ref-pages page)) (get filters true))
|
||||
(set))]
|
||||
(cond->> ref-blocks
|
||||
(seq exclude-ids)
|
||||
(remove (fn [block]
|
||||
(let [ids (set (map :db/id (:block/path-refs block)))]
|
||||
(seq (set/intersection exclude-ids ids)))))
|
||||
|
||||
(seq include-ids)
|
||||
(remove (fn [block]
|
||||
(let [ids (set (map :db/id (:block/path-refs block)))]
|
||||
(empty? (set/intersection include-ids ids))))))))))
|
||||
|
||||
(defn get-filtered-ref-blocks
|
||||
[ref-blocks filters ref-pages]
|
||||
(let [ref-blocks' (mapcat second ref-blocks)
|
||||
filtered-blocks (filter-blocks ref-blocks' filters ref-pages)]
|
||||
(group-by :block/page filtered-blocks)))
|
||||
|
||||
Reference in New Issue
Block a user