From 420e3613812afded0a0da7f5ddc8ee171bc9b3e1 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 30 Jan 2024 21:17:18 +0800 Subject: [PATCH] fix: async > (d/datoms db :avet :file/path) + (map (fn [e] + {:db/id (:e e) + :file/path (:v e)})))) + (defn get-block-and-children [db name children?] (let [get-children (fn [col] diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 90861b986..1f64e5ba1 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -813,7 +813,7 @@ (rum/defc block-embed < rum/reactive {:init (fn [state] (let [block-id (second (:rum/args state))] - (db-async/ state state->highlighted-item :source-block :block/uuid)] (p/let [repo (state/get-current-repo) - _ (db-async/> (d/q - '[:find ?path ?modified-at - :where - [?file :file/path ?path] - [(get-else $ ?file :file/last-modified-at 0) ?modified-at]] - db) - (seq) - (reverse)))) - (defn get-files-blocks [repo-url paths] (let [paths (set paths) diff --git a/src/main/frontend/db_worker.cljs b/src/main/frontend/db_worker.cljs index a2955d4f1..cd615eae2 100644 --- a/src/main/frontend/db_worker.cljs +++ b/src/main/frontend/db_worker.cljs @@ -285,6 +285,14 @@ result (apply d/q (first inputs) @conn (rest inputs))] (pr-str result)))) + (pull + [_this repo selector-str id-str] + (when-let [conn (worker-state/get-datascript-conn repo)] + (let [selector (edn/read-string selector-str) + id (edn/read-string id-str) + result (d/pull @conn selector id)] + (pr-str result)))) + (pull-many [_this repo selector-str ids-str] (when-let [conn (worker-state/get-datascript-conn repo)] @@ -366,10 +374,11 @@ (let [data (->> (sqlite-common-db/get-initial-data @conn) pr-str)] (async/go - (let [all-pages (sqlite-common-db/get-all-pages @conn)] + (let [all-pages (sqlite-common-db/get-all-pages @conn) + all-files (sqlite-common-db/get-all-files @conn)] (worker-util/post-message :sync-db-changes (pr-str {:repo repo - :tx-data all-pages + :tx-data (concat all-files all-pages) :tx-meta nil})))) data))) diff --git a/src/main/frontend/extensions/tldraw.cljs b/src/main/frontend/extensions/tldraw.cljs index bbdd32c9b..32a07b40b 100644 --- a/src/main/frontend/extensions/tldraw.cljs +++ b/src/main/frontend/extensions/tldraw.cljs @@ -204,7 +204,7 @@ (rum/defc tldraw-app-inner < rum/reactive {:init (fn [state] (let [page-name (first (:rum/args state))] - (db-async/> (db/get-files graph) - (map first)) exclude-files (set (or exclude-files []))] ;; read all files in the repo dir, notify if readdir error - (p/let [[files deleted-files] + (p/let [db-files' (db-async/ (fs/readdir repo-dir :path-only? true) (p/chain (fn [files] (->> files diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 92773840f..3caafc96e 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -11,7 +11,6 @@ [frontend.components.whiteboard :as whiteboard] [frontend.config :as config] [frontend.context.i18n :as i18n] - [frontend.db :as db] [frontend.db.restore :as db-restore] [frontend.db.conn :as conn] [frontend.db.react :as react] @@ -41,7 +40,8 @@ [frontend.mobile.core :as mobile] [cljs-bean.core :as bean] [frontend.handler.test :as test] - [frontend.persist-db.browser :as db-browser])) + [frontend.persist-db.browser :as db-browser] + [frontend.db.async :as db-async])) (defn- set-global-error-notification! [] @@ -87,17 +87,18 @@ ;; install after config is restored (shortcut/refresh!) - (cond - (and (not (seq (db/get-files config/demo-repo))) - ;; Not native local directory - (not (some config/local-file-based-graph? (map :url repos))) - (not (mobile-util/native-platform?)) - (not (config/db-based-graph? repo))) - ;; will execute `(state/set-db-restoring! false)` inside - (repo-handler/setup-demo-repo-if-not-exists!) + (p/let [files (db-async/