From a610cf8cff480939d5ec17c4c892c1357a290348 Mon Sep 17 00:00:00 2001 From: eliot-akira Date: Thu, 7 Oct 2021 16:46:33 +0200 Subject: [PATCH 1/2] treatRawData and treatRawStream: Get values more efficiently with Object.values --- lib/persistence.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/persistence.js b/lib/persistence.js index 4839693..538e523 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -156,7 +156,6 @@ class Persistence { treatRawData (rawData) { const data = rawData.split('\n') const dataById = {} - const tdata = [] const indexes = {} // Last line of every data file is usually blank so not really corrupt @@ -181,7 +180,7 @@ class Persistence { corruptItems / data.length > this.corruptAlertThreshold ) throw new Error(`More than ${Math.floor(100 * this.corruptAlertThreshold)}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`) - tdata.push(...Object.values(dataById)) + const tdata = Object.values(dataById) return { data: tdata, indexes: indexes } } @@ -192,7 +191,6 @@ class Persistence { */ treatRawStream (rawStream, cb) { const dataById = {} - const tdata = [] const indexes = {} // Last line of every data file is usually blank so not really corrupt @@ -224,11 +222,9 @@ class Persistence { return } - Object.keys(dataById).forEach(function (k) { - tdata.push(dataById[k]) - }) + const data = Object.values(dataById) - cb(null, { data: tdata, indexes: indexes }) + cb(null, { data, indexes: indexes }) }) lineStream.on('error', function (err) { From 823db2a17e7b90b7201fea25b913de8275abc6e2 Mon Sep 17 00:00:00 2001 From: eliot-akira Date: Thu, 7 Oct 2021 16:51:17 +0200 Subject: [PATCH 2/2] assert.deepStrictEqual instead of deepEqual --- test/persistence.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/persistence.test.js b/test/persistence.test.js index ec35f02..5fa46e1 100755 --- a/test/persistence.test.js +++ b/test/persistence.test.js @@ -282,7 +282,7 @@ describe('Persistence', function () { const treatedData = result.data const indexes = result.indexes Object.keys(indexes).length.should.equal(1) - assert.deepEqual(indexes.test, { fieldName: 'test', unique: true }) + assert.deepStrictEqual(indexes.test, { fieldName: 'test', unique: true }) treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2)