Skip to content

Commit

Permalink
fix: make db persistence atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk authored and tiensonqin committed Dec 23, 2020
1 parent 5a03d96 commit 5ea4a7a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/frontend/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
(let [file-key (datascript-files-db repo)
non-file-key (datascript-db repo)
file-db (d/db (get-files-conn repo))
non-file-db (d/db (get-conn repo false))]
(p/let [_ (idb/set-item! file-key (db->string file-db))
_ (idb/set-item! non-file-key (db->string non-file-db))]
non-file-db (d/db (get-conn repo false))
file-db-str (db->string file-db)
non-file-db-str (db->string non-file-db)]
(p/let [_ (idb/set-batch! [{:key file-key :value file-db-str}
{:key non-file-key :value non-file-db-str}])]
(state/set-last-persist-transact-id! repo true (get-max-tx-id file-db))
(state/set-last-persist-transact-id! repo false (get-max-tx-id non-file-db)))))

Expand Down

0 comments on commit 5ea4a7a

Please sign in to comment.