Do not emit to regist the number of rows processed in copyto

This commit is contained in:
Daniel García Aubert 2018-06-13 20:06:35 +02:00
parent eb4ba60ba0
commit 5655f26fbd
2 changed files with 4 additions and 7 deletions

View File

@ -74,12 +74,8 @@ function handleCopyTo (logger) {
res.header("Content-Disposition", `attachment; filename=${encodeURIComponent(filename)}`);
res.header("Content-Type", "application/octet-stream");
streamCopy.on('copy-to-end', rows => {
metrics.end(rows);
});
streamCopy.to(
function (err, pgstream, client, done) {
function (err, pgstream, copyToStream, client, done) {
if (err) {
return next(err);
}
@ -120,6 +116,8 @@ function handleCopyTo (logger) {
return next(err);
});
pgstream.on('end', () => metrics.end(copyToStream.rowCount));
pgstream
.on('data', data => metrics.addSize(data.length))
.pipe(res);

View File

@ -29,10 +29,9 @@ module.exports = class StreamCopy extends EventEmitter {
})
.on('end', () => {
done();
this.emit('copy-to-end', copyToStream.rowCount);
});
cb(null, pgstream, client, done);
cb(null, pgstream, copyToStream, client, done);
});
}