From 972ea751530bc42296d64682f8af855ebc513a96 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Sun, 28 Dec 2014 02:13:43 +0100 Subject: [PATCH] Pausing and resuming stream to avoid memory overflow in database migration --- server/lib/databaseMigrateToSequelize.js | 53 +++++++++++------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/server/lib/databaseMigrateToSequelize.js b/server/lib/databaseMigrateToSequelize.js index 153044b6..7deb8061 100644 --- a/server/lib/databaseMigrateToSequelize.js +++ b/server/lib/databaseMigrateToSequelize.js @@ -84,49 +84,44 @@ function migrateData(title, stream, deal, callback) { console.log("Migrating "+title); console.log(); - var number = 0; - var ended = false; - - stream.on("data", function(data) { + var queue = async.queue(function(data, next) { data = JSON.parse(JSON.stringify(data)); data.id = data._id; delete data._id; var queries = deal(data); - var outstandingQueries = queries.length; - if(queries.length == 0) - return check(); - - number++; - - for(var i=0; i