mirror of https://github.com/logseq/logseq
wip: debug
parent
d6e6e4ba28
commit
232c1cb4c2
10
deps.edn
10
deps.edn
|
@ -2,8 +2,14 @@
|
||||||
:deps
|
:deps
|
||||||
{org.clojure/clojure {:mvn/version "1.11.1"}
|
{org.clojure/clojure {:mvn/version "1.11.1"}
|
||||||
rum/rum {:mvn/version "0.12.9"}
|
rum/rum {:mvn/version "0.12.9"}
|
||||||
datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
|
||||||
:sha "f0922f4d10714636711bc0176409290e44ce2feb"}
|
datascript/datascript {:local/root "../../datascript"
|
||||||
|
:exclusions [persistent-sorted-set/persistent-sorted-set]}
|
||||||
|
;; datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
||||||
|
;; :sha "f0922f4d10714636711bc0176409290e44ce2feb"
|
||||||
|
;; :exclusions [persistent-sorted-set/persistent-sorted-set]}
|
||||||
|
|
||||||
|
persistent-sorted-set/persistent-sorted-set {:local/root "../../persistent-sorted-set"}
|
||||||
datascript-transit/datascript-transit {:mvn/version "0.3.0"}
|
datascript-transit/datascript-transit {:mvn/version "0.3.0"}
|
||||||
borkdude/rewrite-edn {:mvn/version "0.4.7"}
|
borkdude/rewrite-edn {:mvn/version "0.4.7"}
|
||||||
funcool/promesa {:mvn/version "4.0.2"}
|
funcool/promesa {:mvn/version "4.0.2"}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
{:deps
|
{:deps
|
||||||
;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
|
;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
|
||||||
{datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
{datascript/datascript {:local/root "../../../../datascript"
|
||||||
:sha "f0922f4d10714636711bc0176409290e44ce2feb"}
|
:exclusions [persistent-sorted-set/persistent-sorted-set]}
|
||||||
|
;; datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
||||||
|
;; :sha "f0922f4d10714636711bc0176409290e44ce2feb"
|
||||||
|
;; :exclusions [persistent-sorted-set/persistent-sorted-set]}
|
||||||
|
|
||||||
|
persistent-sorted-set/persistent-sorted-set {:local/root "../../../../persistent-sorted-set"}
|
||||||
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
|
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
|
||||||
cljs-bean/cljs-bean {:mvn/version "1.5.0"}
|
cljs-bean/cljs-bean {:mvn/version "1.5.0"}
|
||||||
org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"}}
|
org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"}}
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
db-graph?
|
db-graph?
|
||||||
(assoc :block/format :markdown)))
|
(assoc :block/format :markdown)))
|
||||||
default-db/built-in-pages)]
|
default-db/built-in-pages)]
|
||||||
(d/transact! db-conn
|
(d/transact! db-conn built-in-pages))))
|
||||||
(concat
|
|
||||||
[{:schema/version db-schema/version}]
|
|
||||||
built-in-pages)))))
|
|
||||||
|
|
||||||
(defn start-conn
|
(defn start-conn
|
||||||
"Create datascript conn with schema and default data"
|
"Create datascript conn with schema and default data"
|
||||||
|
|
|
@ -10,14 +10,9 @@
|
||||||
[cljs.cache :as cache]
|
[cljs.cache :as cache]
|
||||||
[datascript.core :as d]
|
[datascript.core :as d]
|
||||||
[goog.object :as gobj]
|
[goog.object :as gobj]
|
||||||
[logseq.db.frontend.schema :as db-schema]))
|
[logseq.db.frontend.schema :as db-schema]
|
||||||
|
[datascript.transit :as dt]
|
||||||
(defn- write-transit [data]
|
[clojure.edn :as edn]))
|
||||||
(t/write (t/writer :json) data))
|
|
||||||
|
|
||||||
(defn- read-transit [s]
|
|
||||||
(t/read (t/reader :json) s))
|
|
||||||
|
|
||||||
|
|
||||||
;; Notice: this works only on Node.js environment, it doesn't support browser yet.
|
;; Notice: this works only on Node.js environment, it doesn't support browser yet.
|
||||||
|
|
||||||
|
@ -107,23 +102,33 @@
|
||||||
(let [cache (cache/lru-cache-factory {} :threshold threshold)]
|
(let [cache (cache/lru-cache-factory {} :threshold threshold)]
|
||||||
(reify IStorage
|
(reify IStorage
|
||||||
(-store [_ addr+data-seq]
|
(-store [_ addr+data-seq]
|
||||||
|
(prn :debug :store-addr (map first addr+data-seq))
|
||||||
(prn :debug :store {:addr-data addr+data-seq})
|
(prn :debug :store {:addr-data addr+data-seq})
|
||||||
(let [data (map
|
(let [data (->>
|
||||||
|
(map
|
||||||
(fn [[addr data]]
|
(fn [[addr data]]
|
||||||
{:addr addr
|
#js {:addr addr
|
||||||
:content (write-transit data)})
|
:content (pr-str data)})
|
||||||
addr+data-seq)]
|
addr+data-seq)
|
||||||
(upsert-addr-content! repo (bean/->js data))))
|
(to-array))]
|
||||||
|
(upsert-addr-content! repo data)))
|
||||||
(-restore [_ addr]
|
(-restore [_ addr]
|
||||||
(when-let [content (if (cache/has? cache addr)
|
(let [content (restore-data-from-addr repo addr)]
|
||||||
(do
|
(when (nil? content)
|
||||||
(cache/hit cache addr)
|
(prn :debug :error :addr-not-exists addr))
|
||||||
(cache/lookup cache addr))
|
(prn :debug :restored {:addr addr
|
||||||
(when-let [result (restore-data-from-addr repo addr)]
|
;; :content content
|
||||||
(cache/miss cache addr result)
|
})
|
||||||
result))]
|
(edn/read-string content))
|
||||||
(prn {:content content})
|
;; (when-let [content (if (cache/has? cache addr)
|
||||||
(read-transit content))))))
|
;; (do
|
||||||
|
;; (cache/hit cache addr)
|
||||||
|
;; (cache/lookup cache addr))
|
||||||
|
;; (when-let [result (restore-data-from-addr repo addr)]
|
||||||
|
;; (cache/miss cache addr result)
|
||||||
|
;; result))]
|
||||||
|
;; (edn/read-string content))
|
||||||
|
))))
|
||||||
|
|
||||||
(defn open-db!
|
(defn open-db!
|
||||||
[graphs-dir db-name]
|
[graphs-dir db-name]
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
{:deps
|
{:deps
|
||||||
;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
|
;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
|
||||||
{datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
{datascript/datascript {:local/root "../../../../datascript"
|
||||||
:sha "f0922f4d10714636711bc0176409290e44ce2feb"}
|
:exclusions [persistent-sorted-set/persistent-sorted-set]}
|
||||||
|
persistent-sorted-set/persistent-sorted-set {:local/root "../../persistent-sorted-set"}
|
||||||
|
;; datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
|
||||||
|
;; :sha "f0922f4d10714636711bc0176409290e44ce2feb"}
|
||||||
logseq/db {:local/root "../db"}
|
logseq/db {:local/root "../db"}
|
||||||
com.cognitect/transit-cljs {:mvn/version "0.8.280"}}
|
com.cognitect/transit-cljs {:mvn/version "0.8.280"}}
|
||||||
:aliases
|
:aliases
|
||||||
|
|
|
@ -141,10 +141,6 @@
|
||||||
;; TODO: Store schema in sqlite
|
;; TODO: Store schema in sqlite
|
||||||
;; (db-migrate/migrate attached-db)
|
;; (db-migrate/migrate attached-db)
|
||||||
|
|
||||||
(d/transact! conn [(react/kv :db/type "db")
|
|
||||||
{:schema/version db-schema/version}]
|
|
||||||
{:skip-persist? true})
|
|
||||||
|
|
||||||
(when-not electron?
|
(when-not electron?
|
||||||
(js/setTimeout
|
(js/setTimeout
|
||||||
(fn []
|
(fn []
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
[frontend.date :as date]
|
[frontend.date :as date]
|
||||||
[frontend.db :as db]
|
[frontend.db :as db]
|
||||||
[frontend.db.restore :as db-restore]
|
[frontend.db.restore :as db-restore]
|
||||||
|
[logseq.db.frontend.schema :as db-schema]
|
||||||
[frontend.fs :as fs]
|
[frontend.fs :as fs]
|
||||||
[frontend.fs.nfs :as nfs]
|
[frontend.fs.nfs :as nfs]
|
||||||
[frontend.handler.file :as file-handler]
|
[frontend.handler.file :as file-handler]
|
||||||
|
@ -546,8 +547,8 @@
|
||||||
_ (start-repo-db-if-not-exists! full-graph-name)
|
_ (start-repo-db-if-not-exists! full-graph-name)
|
||||||
_ (state/add-repo! {:url full-graph-name})
|
_ (state/add-repo! {:url full-graph-name})
|
||||||
_ (route-handler/redirect-to-home!)
|
_ (route-handler/redirect-to-home!)
|
||||||
_ (db/transact! full-graph-name [(react/kv :db/type "db")]
|
_ (db/transact! full-graph-name [(react/kv :db/type "db")
|
||||||
{:skip-persist? true})
|
(react/kv :schema/version db-schema/version)])
|
||||||
initial-data (sqlite-util/build-db-initial-data config/config-default-content)
|
initial-data (sqlite-util/build-db-initial-data config/config-default-content)
|
||||||
_ (db/transact! full-graph-name initial-data)
|
_ (db/transact! full-graph-name initial-data)
|
||||||
_ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
_ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
||||||
|
|
|
@ -79,16 +79,19 @@
|
||||||
(let [tx-meta (:tx-meta tx-report)
|
(let [tx-meta (:tx-meta tx-report)
|
||||||
{:keys [compute-path-refs? from-disk? new-graph? replace?]} tx-meta]
|
{:keys [compute-path-refs? from-disk? new-graph? replace?]} tx-meta]
|
||||||
(when (and (not from-disk?)
|
(when (and (not from-disk?)
|
||||||
(not new-graph?)
|
(not new-graph?))
|
||||||
(not compute-path-refs?))
|
(try
|
||||||
|
|
||||||
(reset-editing-block-content! (:tx-data tx-report) tx-meta)
|
(reset-editing-block-content! (:tx-data tx-report) tx-meta)
|
||||||
|
(catch :default e
|
||||||
|
(prn :reset-editing-block-content)
|
||||||
|
(js/console.error e)))
|
||||||
|
|
||||||
(let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
|
(let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
|
||||||
repo (state/get-current-repo)
|
repo (state/get-current-repo)
|
||||||
tx (util/profile
|
tx (when-not compute-path-refs?
|
||||||
|
(util/profile
|
||||||
"Compute path refs: "
|
"Compute path refs: "
|
||||||
(set (compute-block-path-refs-tx tx-report blocks)))
|
(set (compute-block-path-refs-tx tx-report blocks))))
|
||||||
tx-report' (if (seq tx)
|
tx-report' (if (seq tx)
|
||||||
(let [refs-tx-data' (:tx-data (db/transact! repo tx {:outliner/transact? true
|
(let [refs-tx-data' (:tx-data (db/transact! repo tx {:outliner/transact? true
|
||||||
:replace? true
|
:replace? true
|
||||||
|
@ -99,23 +102,21 @@
|
||||||
importing? (:graph/importing @state/state)
|
importing? (:graph/importing @state/state)
|
||||||
deleted-block-uuids (set (outliner-pipeline/filter-deleted-blocks (:tx-data tx-report)))]
|
deleted-block-uuids (set (outliner-pipeline/filter-deleted-blocks (:tx-data tx-report)))]
|
||||||
|
|
||||||
(when (and (seq deleted-block-uuids) (not replace?))
|
(when (and (seq deleted-block-uuids) (not replace?)
|
||||||
|
(not compute-path-refs?))
|
||||||
(delete-property-parent-block-if-empty! repo tx-report deleted-block-uuids))
|
(delete-property-parent-block-if-empty! repo tx-report deleted-block-uuids))
|
||||||
|
|
||||||
(when-not importing?
|
|
||||||
(react/refresh! repo tx-report'))
|
|
||||||
|
|
||||||
(when (and (not (:skip-persist? tx-meta))
|
|
||||||
(not replace?)
|
|
||||||
(not (:update-tx-ids? tx-meta)))
|
|
||||||
(let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report'))
|
(let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report'))
|
||||||
updated-blocks (remove (fn [b] (contains? (set deleted-block-uuids) (:block/uuid b))) blocks)
|
updated-blocks (remove (fn [b] (contains? (set deleted-block-uuids) (:block/uuid b))) blocks)
|
||||||
tx-id (get-in tx-report' [:tempids :db/current-tx])
|
tx-id (get-in tx-report' [:tempids :db/current-tx])
|
||||||
update-tx-ids (map (fn [b]
|
update-tx-ids (->>
|
||||||
|
(map (fn [b]
|
||||||
(when-let [db-id (:db/id b)]
|
(when-let [db-id (:db/id b)]
|
||||||
{:db/id db-id
|
{:db/id db-id
|
||||||
:block/tx-id tx-id})) updated-blocks)]
|
:block/tx-id tx-id})) updated-blocks)
|
||||||
(when (seq update-tx-ids)
|
(remove nil?))]
|
||||||
|
(when (and (seq update-tx-ids)
|
||||||
|
(not (:update-tx-ids? tx-meta)))
|
||||||
(db/transact! repo update-tx-ids {:replace? true
|
(db/transact! repo update-tx-ids {:replace? true
|
||||||
:update-tx-ids? true}))
|
:update-tx-ids? true}))
|
||||||
(when (config/db-based-graph? repo)
|
(when (config/db-based-graph? repo)
|
||||||
|
@ -123,7 +124,10 @@
|
||||||
(go
|
(go
|
||||||
(if (util/electron?)
|
(if (util/electron?)
|
||||||
(<! (persist-db/<transact-data repo (:tx-data tx-report) (:tx-meta tx-report)))
|
(<! (persist-db/<transact-data repo (:tx-data tx-report) (:tx-meta tx-report)))
|
||||||
(<! (persist-db/<transact-data repo upsert-blocks deleted-block-uuids))))))))
|
(<! (persist-db/<transact-data repo upsert-blocks deleted-block-uuids)))))))
|
||||||
|
|
||||||
|
(when-not importing?
|
||||||
|
(react/refresh! repo tx-report'))
|
||||||
|
|
||||||
(when (and (not (:delete-files? tx-meta))
|
(when (and (not (:delete-files? tx-meta))
|
||||||
(not replace?))
|
(not replace?))
|
||||||
|
|
Loading…
Reference in New Issue