Bläddra i källkod

Revert "refactor: add :client-ops-db in *sqlite-conns"

This reverts commit f1b1bd247af01f5725276e055da5af669b7bf6c8.
rcmerci 1 år sedan
förälder
incheckning
90e85bc085
2 ändrade filer med 17 tillägg och 21 borttagningar
  1. 12 16
      src/main/frontend/db_worker.cljs
  2. 5 5
      src/main/frontend/worker/state.cljs

+ 12 - 16
src/main/frontend/db_worker.cljs

@@ -127,52 +127,48 @@
       (restore-data-from-addr repo addr))))
 
 (defn- close-db-aux!
-  [repo ^Object db ^Object search ^Object client-ops-db]
+  [repo ^Object db ^Object search]
   (swap! *sqlite-conns dissoc repo)
   (swap! *datascript-conns dissoc repo)
   (when db (.close db))
   (when search (.close search))
-  (when client-ops-db (.close client-ops-db))
   (when-let [^js pool (worker-state/get-opfs-pool repo)]
     (.releaseAccessHandles pool))
   (swap! *opfs-pools dissoc repo))
 
 (defn- close-other-dbs!
   [repo]
-  (doseq [[r {:keys [db search client-ops-db]}] @*sqlite-conns]
+  (doseq [[r {:keys [db search]}] @*sqlite-conns]
     (when-not (= repo r)
-      (close-db-aux! r db search client-ops-db))))
+      (close-db-aux! r db search))))
 
 (defn close-db!
   [repo]
-  (let [{:keys [db search client-ops-db]} (@*sqlite-conns repo)]
-    (close-db-aux! repo db search client-ops-db)))
+  (let [{:keys [db search]} (@*sqlite-conns repo)]
+    (close-db-aux! repo db search)))
 
-(defn- get-dbs
-  "Return [db search-db client-ops-db]"
+(defn- get-db-and-search-db
   [repo]
   (if @*publishing?
     (p/let [^object DB (.-DB ^object (.-oo1 ^object @*sqlite))
             db (new DB "/db.sqlite" "c")
             search-db (new DB "/search-db.sqlite" "c")]
-      [db search-db nil])
+      [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))
-            client-ops-db (new (.-OpfsSAHPoolDb pool) (str "client-ops--" repo-path))]
-      [db search-db client-ops-db])))
+            search-db (new (.-OpfsSAHPoolDb pool) (str "search" repo-path))]
+      [db search-db])))
 
 (defn- create-or-open-db!
   [repo {:keys [config]}]
   (when-not (worker-state/get-sqlite-conn repo)
-    (p/let [[db search-db client-ops-db] (get-dbs repo)
+    (p/let [[db search-db] (get-db-and-search-db repo)
             storage (new-sqlite-storage repo {})]
       (swap! *sqlite-conns assoc repo {:db db
-                                       :search search-db
-                                       :client-ops-db client-ops-db})
+                                       :search search-db})
       (.exec db "PRAGMA locking_mode=exclusive")
       (sqlite-common-db/create-kvs-table! db)
       (search/create-tables-and-triggers! search-db)
@@ -259,7 +255,7 @@
 
 (defn- get-search-db
   [repo]
-  (worker-state/get-sqlite-conn repo :search))
+  (worker-state/get-sqlite-conn repo {:search? true}))
 
 (defn- with-write-transit-str
   [p]

+ 5 - 5
src/main/frontend/worker/state.cljs

@@ -40,11 +40,11 @@
 (defonce *opfs-pools (atom nil))
 
 (defn get-sqlite-conn
-  "which-db: enum of [:db :search :client-ops-db], default :db"
-  ([repo] (get-sqlite-conn repo :db))
-  ([repo which-db]
-   (assert (contains? #{:db :search :client-ops-db} which-db) which-db)
-   (get-in @*sqlite-conns [repo which-db])))
+  [repo & {:keys [search?]
+           :or {search? false}
+           :as _opts}]
+  (let [k (if search? :search :db)]
+    (get-in @*sqlite-conns [repo k])))
 
 (defn get-datascript-conn
   [repo]