|
|
@@ -49,7 +49,6 @@
|
|
|
[logseq.db.common.sqlite :as common-sqlite]
|
|
|
[logseq.db.common.view :as db-view]
|
|
|
[logseq.db.frontend.class :as db-class]
|
|
|
- [logseq.db.frontend.schema :as db-schema]
|
|
|
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
|
|
[logseq.db.sqlite.export :as sqlite-export]
|
|
|
[logseq.db.sqlite.gc :as sqlite-gc]
|
|
|
@@ -106,44 +105,6 @@
|
|
|
[^js pool data]
|
|
|
(.importDb ^js pool repo-path data))
|
|
|
|
|
|
-(defn- get-all-datoms-from-sqlite-db
|
|
|
- [db]
|
|
|
- (some->> (.exec db #js {:sql "select * from kvs"
|
|
|
- :rowMode "array"})
|
|
|
- bean/->clj
|
|
|
- (mapcat
|
|
|
- (fn [[_addr content _addresses]]
|
|
|
- (let [content' (sqlite-util/transit-read content)
|
|
|
- datoms (when (map? content')
|
|
|
- (:keys content'))]
|
|
|
- datoms)))
|
|
|
- distinct
|
|
|
- (map (fn [[e a v t]]
|
|
|
- (d/datom e a v t)))))
|
|
|
-
|
|
|
-(defn- rebuild-db-from-datoms!
|
|
|
- "Persistent-sorted-set has been broken, used addresses can't be found"
|
|
|
- [datascript-conn sqlite-db]
|
|
|
- (let [datoms (get-all-datoms-from-sqlite-db sqlite-db)
|
|
|
- db (d/init-db [] db-schema/schema
|
|
|
- {:storage (storage/storage @datascript-conn)})
|
|
|
- db (d/db-with db
|
|
|
- (map (fn [d]
|
|
|
- [:db/add (:e d) (:a d) (:v d) (:t d)]) datoms))]
|
|
|
- (prn :debug :rebuild-db-from-datoms :datoms-count (count datoms))
|
|
|
- (worker-util/post-message :notification ["The SQLite db will be exported to avoid any data-loss." :warning false])
|
|
|
- (worker-util/post-message :export-current-db [])
|
|
|
- (.exec sqlite-db #js {:sql "delete from kvs"})
|
|
|
- (d/reset-conn! datascript-conn db)))
|
|
|
-
|
|
|
-(defn- fix-broken-graph
|
|
|
- [graph]
|
|
|
- (let [conn (worker-state/get-datascript-conn graph)
|
|
|
- sqlite-db (worker-state/get-sqlite-conn graph)]
|
|
|
- (when (and conn sqlite-db)
|
|
|
- (rebuild-db-from-datoms! conn sqlite-db)
|
|
|
- (worker-util/post-message :notification ["The graph has been successfully rebuilt." :success false]))))
|
|
|
-
|
|
|
(defn upsert-addr-content!
|
|
|
"Upsert addr+data-seq. Update sqlite-cli/upsert-addr-content! when making changes"
|
|
|
[db data]
|
|
|
@@ -750,10 +711,6 @@
|
|
|
[repo]
|
|
|
(get-all-page-titles-with-cache repo))
|
|
|
|
|
|
-(def-thread-api :thread-api/fix-broken-graph
|
|
|
- [graph]
|
|
|
- (fix-broken-graph graph))
|
|
|
-
|
|
|
(def-thread-api :thread-api/reset-file
|
|
|
[repo file-path content opts]
|
|
|
;; (prn :debug :reset-file :file-path file-path :opts opts)
|