fix: load all pages and files when app starts

pull/10933/head
Tienson Qin 2024-02-01 17:04:44 +08:00
parent d110dc41b4
commit 3dfe5c5751
2 changed files with 19 additions and 18 deletions

View File

@ -89,9 +89,9 @@
(defn get-initial-data
"Returns initial data"
[db]
(let [files (get-built-in-files db)
journals (get-latest-journals db 3)]
(concat files journals)))
(let [all-pages (get-all-pages db)
all-files (get-all-files db)]
(concat all-pages all-files)))
(defn restore-initial-data
"Given initial sqlite data and schema, returns a datascript connection"

View File

@ -260,7 +260,7 @@
[_this repo & {:keys [close-other-db?]
:or {close-other-db? true}}]
(p/do!
(when close-other-db?
(when close-other-db?
(close-other-dbs! repo))
(create-or-open-db! repo)))
@ -364,20 +364,21 @@
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [data (->> (sqlite-common-db/get-initial-data @conn)
pr-str)]
(async/go
;; TODO: after UI db transacted
(async/<! (async/timeout 500))
(let [all-pages (sqlite-common-db/get-all-pages @conn)
all-files (sqlite-common-db/get-all-files @conn)
full-data (concat all-files all-pages)
partitioned-data (map-indexed (fn [idx p] [idx p]) (partition-all 2000 full-data))]
(doseq [[idx tx-data] partitioned-data]
(worker-util/post-message :sync-db-changes (pr-str
{:repo repo
:tx-data tx-data
:tx-meta {:initial-pages? true
:end? (= idx (dec (count partitioned-data)))}}))
(async/<! (async/timeout 100)))))
;; (comment
;; (async/go
;; ;; TODO: after UI db transacted
;; (async/<! (async/timeout 500))
;; (let [all-pages (sqlite-common-db/get-all-pages @conn)
;; all-files (sqlite-common-db/get-all-files @conn)
;; full-data (concat all-files all-pages)
;; partitioned-data (map-indexed (fn [idx p] [idx p]) (partition-all 2000 full-data))]
;; (doseq [[idx tx-data] partitioned-data]
;; (worker-util/post-message :sync-db-changes (pr-str
;; {:repo repo
;; :tx-data tx-data
;; :tx-meta {:initial-pages? true
;; :end? (= idx (dec (count partitioned-data)))}}))
;; (async/<! (async/timeout 100))))))
data)))
(closeDB