hook up DB pipeline

This commit is contained in:
Junyi Du
2022-10-27 03:41:15 +08:00
committed by Tienson Qin
parent b760684847
commit 49336a96b7
5 changed files with 26 additions and 7 deletions

View File

@@ -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]

View File

@@ -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 %))

View File

@@ -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!
([]

View File

@@ -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]

View File

@@ -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)))