fix: persist on disk when importing sqlite or switching graphs

pull/10639/head
Tienson Qin 2023-12-12 23:39:31 +08:00
parent 215d3739b9
commit 32711678ff
4 changed files with 23 additions and 18 deletions

View File

@ -73,7 +73,8 @@
[logseq.graph-parser.config :as gp-config]
[promesa.core :as p]
[rum.core :as rum]
[frontend.db.listener :as db-listener]))
[frontend.db.listener :as db-listener]
[frontend.persist-db :as persist-db]))
;; TODO: should we move all events here?
@ -186,8 +187,15 @@
(when persist?
(when (util/electron?)
(p/do!
(when (config/local-file-based-graph? current-repo)
(repo-handler/persist-db! current-repo persist-db-noti-m)))))
(cond
(config/db-based-graph? current-repo)
(persist-db/<export-db current-repo {})
(config/local-file-based-graph? current-repo)
(repo-handler/persist-db! current-repo persist-db-noti-m)
:else
nil))))
(repo-handler/restore-and-setup-repo! graph)
(graph-switch graph)
state/set-state! :sync-graph/init? false)))

View File

@ -229,6 +229,7 @@
(p/then
(fn [_result]
(state/set-current-repo! graph)
(persist-db/<export-db graph {})
(finished-ok-handler)))
(p/catch
(fn [e]

View File

@ -23,14 +23,6 @@
(defn <transact-data [repo tx-data tx-meta]
(protocol/<transact-data (get-impl) repo tx-data tx-meta))
(defn <fetch-init-data
([repo]
(<fetch-init-data repo {}))
([repo opts]
(p/let [ret (protocol/<fetch-initial-data (get-impl) repo opts)]
(js/console.log "fetch-initial-data" ret)
ret)))
(defn <export-db
[repo opts]
(protocol/<export-db (get-impl) repo opts))
@ -39,15 +31,19 @@
[repo data]
(protocol/<import-db (get-impl) repo data))
(defn <fetch-init-data
([repo]
(<fetch-init-data repo {}))
([repo opts]
(p/let [ret (protocol/<fetch-initial-data (get-impl) repo opts)]
(js/console.log "fetch-initial-data" ret)
ret)))
;; FIXME: limit repo name's length
;; @shuyu Do we still need this?
(defn <new [repo]
{:pre [(<= (count repo) 56)]}
(p/do!
(let [current-repo (state/get-current-repo)]
(when (and (util/electron?)
(not= repo current-repo)
(config/db-based-graph? current-repo))
;; switch graph
(<export-db current-repo {}))
(<export-db current-repo {})
(protocol/<new (get-impl) repo))))

View File

@ -41,10 +41,10 @@
(defn <export-db!
[repo data]
(cond
(util/electron?)
(and (util/electron?) (config/db-based-graph? repo))
(ipc/ipc :db-export repo data)
;; nfs-supported? auto backup
;; TODO: browser nfs-supported? auto backup
;;
:else