mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 10:26:35 +00:00
hook up DB pipeline
This commit is contained in:
@@ -785,6 +785,8 @@
|
||||
react)))))
|
||||
|
||||
(defn get-page-blocks-no-cache
|
||||
"Return blocks of the designated page, without using cache.
|
||||
page - name / title of the page"
|
||||
([page]
|
||||
(get-page-blocks-no-cache (state/get-current-repo) page nil))
|
||||
([repo-url page]
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
nil)))
|
||||
|
||||
(defn get-entity-from-db-after-or-before
|
||||
"Get the entity from db after if possible; otherwise get entity from db before
|
||||
Useful for fetching deleted elements"
|
||||
[db-before db-after db-id]
|
||||
(let [r (safe-pull db-after '[*] db-id)]
|
||||
(if (= keys-of-deleted-entity (count r))
|
||||
@@ -21,6 +23,7 @@
|
||||
r)))
|
||||
|
||||
(defn get-blocks-and-pages
|
||||
"Calculate updated blocks and pages based on the db-before and db-after from tx-report"
|
||||
[{:keys [db-before db-after tx-data tx-meta]}]
|
||||
(let [updated-db-ids (-> (mapv first tx-data) (set))
|
||||
result (reduce
|
||||
@@ -39,6 +42,7 @@
|
||||
{:blocks #{}
|
||||
:pages #{}}
|
||||
updated-db-ids)
|
||||
;; updated pages logged in tx-meta (usually from move op)
|
||||
tx-meta-pages (->> [(:from-page tx-meta) (:target-page tx-meta)]
|
||||
(remove nil?)
|
||||
(map #(get-entity-from-db-after-or-before db-before db-after %))
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
(fn [datom]
|
||||
(contains? #{:block/name :block/content} (:a datom)))
|
||||
data)
|
||||
diff-pages (:pages (ds-report/get-blocks-and-pages tx-report))]
|
||||
updated-pages (:pages (ds-report/get-blocks-and-pages tx-report))]
|
||||
(when (seq datoms)
|
||||
(let [datoms (group-by :a datoms)
|
||||
pages (:block/name datoms)
|
||||
@@ -252,7 +252,16 @@
|
||||
(set))]
|
||||
(transact-blocks! repo
|
||||
{:blocks-to-remove-set blocks-to-remove-set
|
||||
:blocks-to-add blocks-to-add})))))))
|
||||
:blocks-to-add blocks-to-add})))))
|
||||
(when (seq updated-pages) ;; when move op happens, no :block/content provided
|
||||
(let [affected-pages (-> (map :block/name updated-pages)
|
||||
distinct)
|
||||
pages-to-add-set (filter db/page-exists? affected-pages)
|
||||
pages-to-add (->> (map search-db/page->index pages-to-add-set)
|
||||
(remove nil?))
|
||||
pages-to-remove-set (remove db/page-exists? affected-pages)]
|
||||
(transact-pages! repo {:pages-to-remove-set pages-to-remove-set
|
||||
:pages-to-add pages-to-add})))))
|
||||
|
||||
(defn rebuild-indices!
|
||||
([]
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
(doseq [block blocks-to-add]
|
||||
(.add indice (bean/->js block)))))
|
||||
indice)))
|
||||
(transact-pages! [_this _data] nil) ;; Page index is not available with fuse.js until sufficient performance benchmarking
|
||||
(truncate-blocks! [_this]
|
||||
(swap! indices assoc-in [repo :blocks] nil))
|
||||
(remove-db! [_this]
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
:page page
|
||||
:content content})))
|
||||
|
||||
;; TODO Junyi: Finalize index code
|
||||
(defn page->index
|
||||
"Convert a page name to the index for searching (page content level)"
|
||||
[page-name]
|
||||
:no-op)
|
||||
|
||||
(defn build-blocks-indice
|
||||
;; TODO: Remove repo effects fns further up the call stack. db fns need standardization on taking connection
|
||||
#_:clj-kondo/ignore
|
||||
@@ -29,12 +35,9 @@
|
||||
(remove nil?)
|
||||
(bean/->js)))
|
||||
|
||||
;; TODO Junyi: Finalize index code
|
||||
(defn build-pages-indice
|
||||
;; TODO: Remove repo effects fns further up the call stack. db fns need standardization on taking connection
|
||||
#_:clj-kondo/ignore
|
||||
(defn build-pages-indice
|
||||
[repo]
|
||||
(->> (db/get-all-page-contents)
|
||||
(->> (db/get-all-pages repo)
|
||||
(map page->index)
|
||||
(remove nil?)
|
||||
(bean/->js)))
|
||||
|
||||
Reference in New Issue
Block a user