From 275ab89f0053efa4e2a17f73232bdb5b5abf82b4 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Tue, 26 Apr 2022 16:43:20 -0500 Subject: [PATCH] Reduce memory usage on saveList --- build-lists.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/build-lists.js b/build-lists.js index 4425712..d2b80f7 100644 --- a/build-lists.js +++ b/build-lists.js @@ -159,20 +159,15 @@ class BuildLists { const saveableList = saveMethod( this.lists[listOptions.name] ) - console.log('saveableList', typeof saveableList) + // console.log('saveableList', typeof saveableList) + + // Stringify one at a time to allow for large lists + const saveableListJSON = '[' + saveableList.map(el => JSON.stringify(el)).join(',') + ']' // Write the list to JSON - await fs.writeFile(listFullPath, JSON.stringify( saveableList )) + await fs.writeFile(listFullPath, saveableListJSON) - // Read back the JSON we just wrote to ensure it exists - const savedListJSON = await fs.readFile(listFullPath, 'utf-8') - - // console.log('savedListJSON', savedListJSON) - - const savedList = JSON.parse(savedListJSON) - - // Import the created JSON File - return savedList + return } // Run all listsOprions methods