mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix: don't save transit for db-based graphs
This commit is contained in:
@@ -208,7 +208,16 @@
|
||||
(fs-extra/ensureDirSync dir)
|
||||
dir))
|
||||
|
||||
(defn- get-graphs
|
||||
(defn- get-db-based-graphs-dir
|
||||
[]
|
||||
(let [dir (if utils/ci?
|
||||
(.resolve node-path js/__dirname "../tmp/graphs")
|
||||
(.join node-path (.homedir os) "logseq" "graphs"))]
|
||||
(fs-extra/ensureDirSync dir)
|
||||
dir))
|
||||
|
||||
;; TODO: move file based graphs to "~/logseq/graphs" too
|
||||
(defn- get-file-based-graphs
|
||||
"Returns all graph names in the cache directory (starting with `logseq_local_`)"
|
||||
[]
|
||||
(let [dir (get-graphs-dir)]
|
||||
@@ -217,6 +226,21 @@
|
||||
(map #(node-path/basename % ".transit"))
|
||||
(map graph-name->path))))
|
||||
|
||||
(defn- get-db-based-graphs
|
||||
"Returns all graph names in the cache directory (starting with `logseq_db_`)"
|
||||
[]
|
||||
(let [dir (get-db-based-graphs-dir)]
|
||||
(->> (common-graph/readdir dir)
|
||||
(remove #{dir})
|
||||
(map node-path/basename)
|
||||
(map graph-name->path))))
|
||||
|
||||
(defn- get-graphs
|
||||
[]
|
||||
(concat
|
||||
(get-file-based-graphs)
|
||||
(get-db-based-graphs)))
|
||||
|
||||
;; TODO support alias mechanism
|
||||
(defn get-graph-name
|
||||
"Given a graph's name of string, returns the graph's fullname.
|
||||
|
||||
@@ -7,15 +7,17 @@
|
||||
[frontend.util :as util]
|
||||
[promesa.core :as p]
|
||||
[electron.ipc :as ipc]
|
||||
[datascript.core :as d]))
|
||||
[datascript.core :as d]
|
||||
[frontend.config :as config]))
|
||||
|
||||
;; persisting DBs between page reloads
|
||||
(defn persist! [repo]
|
||||
(let [key (conn/datascript-db repo)
|
||||
db (conn/get-db repo)]
|
||||
(when db
|
||||
(let [db-str (if db (db-utils/db->string db) "")]
|
||||
(p/let [_ (db-persist/save-graph! key db-str)])))))
|
||||
(when-not (config/db-based-graph? repo)
|
||||
(let [key (conn/datascript-db repo)
|
||||
db (conn/get-db repo)]
|
||||
(when db
|
||||
(let [db-str (if db (db-utils/db->string db) "")]
|
||||
(p/let [_ (db-persist/save-graph! key db-str)]))))))
|
||||
|
||||
(defonce persistent-jobs (atom {}))
|
||||
|
||||
@@ -27,19 +29,20 @@
|
||||
(defn persist-if-idle!
|
||||
[repo]
|
||||
(clear-repo-persistent-job! repo)
|
||||
(let [job (js/setTimeout
|
||||
(fn []
|
||||
(if (and (state/input-idle? repo)
|
||||
(state/db-idle? repo)
|
||||
(when-not (config/db-based-graph? repo)
|
||||
(let [job (js/setTimeout
|
||||
(fn []
|
||||
(if (and (state/input-idle? repo)
|
||||
(state/db-idle? repo)
|
||||
;; It's ok to not persist here since new changes
|
||||
;; will be notified when restarting the app.
|
||||
(not (state/whiteboard-route?)))
|
||||
(persist! repo)
|
||||
(not (state/whiteboard-route?)))
|
||||
(persist! repo)
|
||||
;; (state/set-db-persisted! repo true)
|
||||
|
||||
(persist-if-idle! repo)))
|
||||
3000)]
|
||||
(swap! persistent-jobs assoc repo job)))
|
||||
(persist-if-idle! repo)))
|
||||
3000)]
|
||||
(swap! persistent-jobs assoc repo job))))
|
||||
|
||||
;; only save when user's idle
|
||||
|
||||
|
||||
@@ -545,7 +545,7 @@
|
||||
(p/let [full-graph-name (str config/db-version-prefix graph)
|
||||
_ (start-repo-db-if-not-exists! full-graph-name)
|
||||
_ (state/add-repo! {:url full-graph-name})
|
||||
_ (ipc/ipc :db-new graph)
|
||||
_ (ipc/ipc :db-new full-graph-name)
|
||||
_ (db/transact! full-graph-name [(react/kv :db/type "db")]
|
||||
{:skip-persist? true})
|
||||
initial-data [{:file/path (str "logseq/" "config.edn")
|
||||
|
||||
Reference in New Issue
Block a user