Verified Commit 142e5d35 authored by Aral Balkan's avatar Aral Balkan
Browse files

Write tables using fast-write-atomic

parent ec920858
......@@ -16,6 +16,8 @@ const fs = require('fs-extra')
const path = require('path')
const { log, needsToBeProxified } = require('./util')
const isProxy = require('util').types.isProxy
const { promisify } = require('util')
const fastWriteAtomic = promisify(require('fast-write-atomic'))
const { performance } = require('perf_hooks')
......@@ -137,7 +139,7 @@ class WhatTable {
const tableContents = JSON.stringify(this.dataProxy)
const t2 = performance.now()
log(` 💾 ❨WhatDB?❩ ╰─ Stringified in ${(t2-t1).toFixed(3)} ms.`)
await fs.writeFile(this.tablePath, tableContents)
await fastWriteAtomic(this.tablePath, tableContents)
const t3 = performance.now()
log(` 💾 ❨WhatDB?❩ ╰─ Wrote in ${(t3-t2).toFixed(3)} ms.`)
this.isSaving = false
......
......@@ -598,6 +598,11 @@
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
},
"fast-write-atomic": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/fast-write-atomic/-/fast-write-atomic-0.2.1.tgz",
"integrity": "sha512-WvJe06IfNYlr+6cO3uQkdKdy3Cb1LlCJSF8zRs2eT8yuhdbSlR9nIt+TgQ92RUxiRrQm+/S7RARnMfCs5iuAjw=="
},
"figures": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
......
......@@ -26,6 +26,7 @@
"author": "Aral Balkan",
"license": "AGPL-3.0-or-later",
"dependencies": {
"fast-write-atomic": "^0.2.1",
"fs-extra": "^9.0.1"
},
"devDependencies": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment