|
|
@@ -29,6 +29,7 @@
|
|
|
(defonce *sqlite-conns worker-state/*sqlite-conns)
|
|
|
(defonce *datascript-conns worker-state/*datascript-conns)
|
|
|
(defonce *opfs-pools worker-state/*opfs-pools)
|
|
|
+(defonce *publishing? (atom false))
|
|
|
|
|
|
(defn- get-pool-name
|
|
|
[graph-name]
|
|
|
@@ -36,16 +37,21 @@
|
|
|
|
|
|
(defn- <get-opfs-pool
|
|
|
[graph]
|
|
|
- (or (worker-state/get-opfs-pool graph)
|
|
|
- (p/let [^js pool (.installOpfsSAHPoolVfs @*sqlite #js {:name (get-pool-name graph)
|
|
|
- :initialCapacity 20})]
|
|
|
- (swap! *opfs-pools assoc graph pool)
|
|
|
- pool)))
|
|
|
+ (when-not @*publishing?
|
|
|
+ (or (worker-state/get-opfs-pool graph)
|
|
|
+ (p/let [^js pool (.installOpfsSAHPoolVfs @*sqlite #js {:name (get-pool-name graph)
|
|
|
+ :initialCapacity 20})]
|
|
|
+ (swap! *opfs-pools assoc graph pool)
|
|
|
+ pool))))
|
|
|
|
|
|
(defn- init-sqlite-module!
|
|
|
[]
|
|
|
(when-not @*sqlite
|
|
|
- (p/let [electron? (string/includes? (.. js/location -href) "electron=true")
|
|
|
+ (p/let [href (.. js/location -href)
|
|
|
+ electron? (string/includes? href "electron=true")
|
|
|
+ publishing? (string/includes? href "publishing=true")
|
|
|
+
|
|
|
+ _ (reset! *publishing? publishing?)
|
|
|
base-url (str js/self.location.protocol "//" js/self.location.host)
|
|
|
sqlite-wasm-url (if electron?
|
|
|
(js/URL. "sqlite3.wasm" (.. js/location -href))
|
|
|
@@ -131,15 +137,26 @@
|
|
|
(let [{:keys [db search]} (@*sqlite-conns repo)]
|
|
|
(close-db-aux! repo db search)))
|
|
|
|
|
|
-(defn- create-or-open-db!
|
|
|
+(defn- get-db-and-search-db
|
|
|
[repo]
|
|
|
- (when-not (worker-state/get-sqlite-conn repo)
|
|
|
+ (if @*publishing?
|
|
|
+ (p/let [^object DB (.-DB ^object (.-oo1 ^object @*sqlite))
|
|
|
+ db (new DB "/db.sqlite" "ct")
|
|
|
+ search-db (new DB "/search-db.sqlite" "ct")]
|
|
|
+ [db search-db])
|
|
|
(p/let [^js pool (<get-opfs-pool repo)
|
|
|
capacity (.getCapacity pool)
|
|
|
_ (when (zero? capacity) ; file handle already releases since pool will be initialized only once
|
|
|
(.acquireAccessHandles pool))
|
|
|
db (new (.-OpfsSAHPoolDb pool) repo-path)
|
|
|
- search-db (new (.-OpfsSAHPoolDb pool) (str "search" repo-path))
|
|
|
+ search-db (new (.-OpfsSAHPoolDb pool) (str "search" repo-path))]
|
|
|
+ [db search-db])))
|
|
|
+
|
|
|
+(defn- create-or-open-db!
|
|
|
+ [repo]
|
|
|
+ (when-not (worker-state/get-sqlite-conn repo)
|
|
|
+ (p/let [[db search-db] (get-db-and-search-db repo)
|
|
|
+ _ (prn :debug :db db :search-db search-db)
|
|
|
storage (new-sqlite-storage repo {})]
|
|
|
(swap! *sqlite-conns assoc repo {:db db
|
|
|
:search search-db})
|
|
|
@@ -322,7 +339,7 @@
|
|
|
[_this repo]
|
|
|
(<export-db-file repo))
|
|
|
|
|
|
- (importDb
|
|
|
+ ( importDb
|
|
|
[this repo data]
|
|
|
(when-not (string/blank? repo)
|
|
|
(p/let [pool (<get-opfs-pool repo)]
|