perf: only log download progress for big tarballs

This commit is contained in:
Zoltan Kochan
2020-09-12 13:34:35 +03:00
parent c772f06883
commit 7605570e69
2 changed files with 10 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/tarball-fetcher": minor
---
Download progress should be logged only for big tarballs.

View File

@@ -12,6 +12,8 @@ import { BadTarballError } from './errorTypes'
import urlLib = require('url')
import ssri = require('ssri')
const BIG_TARBALL_SIZE = 1024 * 1024 * 5 // 5 MB
class TarballIntegrityError extends PnpmError {
public readonly found: string
public readonly expected: string
@@ -149,7 +151,9 @@ export default (
if (opts.onStart) {
opts.onStart(size, currentAttempt)
}
const onProgress = opts.onProgress
// In order to reduce the amount of logs, we only report the download progress of big tarballs
const onProgress = size != null && size >= BIG_TARBALL_SIZE
? opts.onProgress : undefined
let downloaded = 0
res.body.on('data', (chunk: Buffer) => {
downloaded += chunk.length