fix: no unlinked references

This commit is contained in:
Tienson Qin
2026-05-05 13:44:10 +08:00
parent 13779a4047
commit 6439791230
2 changed files with 18 additions and 19 deletions

View File

@@ -12,7 +12,8 @@
[logseq.shui.hooks :as hooks]
[logseq.shui.ui :as shui]
[missionary.core :as m]
[rum.core :as rum]))
[rum.core :as rum]
[promesa.core :as p]))
(rum/defc references-aux
[page-entity config]
@@ -77,11 +78,10 @@
(when-let [id (:db/id entity)]
(let [[has-references? set-has-references!] (hooks/use-state nil)]
(hooks/use-effect!
#(c.m/run-task*
(m/sp
(let [result (c.m/<? (state/<invoke-db-worker :thread-api/block-refs-check
(state/get-current-repo) id {:unlinked? true}))]
(set-has-references! result))))
(fn []
(p/let [result (state/<invoke-db-worker :thread-api/block-refs-check
(state/get-current-repo) id {:unlinked? true})]
(set-has-references! result)))
[])
(when has-references?
(let [config (assoc config :highlight-query (:block/title entity))]

View File

@@ -707,19 +707,18 @@
(def-thread-api :thread-api/block-refs-check
[repo id {:keys [unlinked?]}]
(m/sp
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [db @conn
block (d/entity db id)]
(if unlinked?
(let [title (string/lower-case (:block/title block))
result (m/? (search-blocks repo title {:limit 100}))]
(boolean (some (fn [b]
(let [block (d/entity db (:db/id b))]
(and (not= id (:db/id block))
(not ((set (map :db/id (:block/refs block))) id))
(string/includes? (string/lower-case (:block/title block)) title)))) result)))
(some? (first (common-initial-data/get-block-refs db (:db/id block)))))))))
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [db @conn
block (d/entity db id)]
(if unlinked?
(let [title (string/lower-case (:block/title block))
result (search-blocks repo title {:limit 100})]
(boolean (some (fn [b]
(let [block (d/entity db (:db/id b))]
(and (not= id (:db/id block))
(not ((set (map :db/id (:block/refs block))) id))
(string/includes? (string/lower-case (:block/title block)) title)))) result)))
(some? (first (common-initial-data/get-block-refs db (:db/id block))))))))
(def-thread-api :thread-api/get-block-parents
[repo id depth]