From 06c40a396bbf72fb2ff441aa747ab435fb5f0e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Thu, 21 Jun 2018 15:58:23 +0200 Subject: [PATCH] copy from: events is series --- app/controllers/copy_controller.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index 0128e7b2..fd31976c 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -114,6 +114,7 @@ function handleCopyFrom (logger) { } req + .on('data', data => isGzip ? metrics.addGzipSize(data.length) : undefined) .on('error', err => { metrics.end(null, err); pgstream.emit('error', err); @@ -122,9 +123,10 @@ function handleCopyFrom (logger) { const err = new Error('Connection closed by client'); pgstream.emit('cancelQuery', err); pgstream.emit('error', err); - }); - - pgstream + }) + .pipe(isGzip ? zlib.createGunzip() : new PassThrough()) + .on('data', data => metrics.addSize(data.length)) + .pipe(pgstream) .on('error', (err) => { metrics.end(null, err); req.unpipe(pgstream); @@ -144,13 +146,6 @@ function handleCopyFrom (logger) { total_rows: rows }); }); - - const middleStream = isGzip ? zlib.createGunzip() : new PassThrough(); - req - .on('data', data => isGzip ? metrics.addGzipSize(data.length) : undefined) - .pipe(middleStream) - .on('data', data => metrics.addSize(data.length)) - .pipe(pgstream); } ); };