Skip to content

Commit

Permalink
perf: enable WAL for all sqlite dbs including search
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 6, 2024
1 parent c9062e0 commit 808e5b4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/frontend/worker/db_worker.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,23 @@
client-ops-db (new (.-OpfsSAHPoolDb pool) (str "client-ops-" repo-path))]
[db search-db client-ops-db])))

(defn- enable-sqlite-wal-mode!
[^Object db]
(.exec db "PRAGMA locking_mode=exclusive")
(.exec db "PRAGMA journal_mode=WAL"))

(defn- create-or-open-db!
[repo {:keys [config import-type]}]
(when-not (worker-state/get-sqlite-conn repo)
(p/let [[db search-db client-ops-db] (get-dbs repo)
(p/let [[db search-db client-ops-db :as dbs] (get-dbs repo)
storage (new-sqlite-storage repo {})
client-ops-storage (when-not @*publishing? (new-sqlite-client-ops-storage repo))
db-based? (sqlite-util/db-based-graph? repo)]
(swap! *sqlite-conns assoc repo {:db db
:search search-db
:client-ops client-ops-db})
(.exec db "PRAGMA locking_mode=exclusive")
(.exec db "PRAGMA journal_mode=WAL")
(.exec client-ops-db "PRAGMA locking_mode=exclusive")
(.exec client-ops-db "PRAGMA journal_mode=WAL")
(doseq [db' dbs]
(enable-sqlite-wal-mode! db'))
(sqlite-common-db/create-kvs-table! db)
(when-not @*publishing? (sqlite-common-db/create-kvs-table! client-ops-db))
(db-migrate/migrate-sqlite-db db)
Expand Down

0 comments on commit 808e5b4

Please sign in to comment.