mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: use fewer system resources to draw the progress bar
There's reason to believe that upgrade scripts will run faster if the system isn't spending a non-insignificant amount of resources simply drawing the progress bar. Closes #7711 Some context: https://github.com/npm/npm/issues/11283
This commit is contained in:
@@ -204,16 +204,18 @@ Upgrade.process = function (files, skipCount, callback) {
|
||||
Upgrade.incrementProgress = function (value) {
|
||||
this.current += value || 1;
|
||||
|
||||
// Redraw the progress bar
|
||||
var percentage = 0;
|
||||
var filled = 0;
|
||||
var unfilled = 15;
|
||||
if (this.total) {
|
||||
percentage = Math.floor((this.current / this.total) * 100) + '%';
|
||||
filled = Math.floor((this.current / this.total) * 15);
|
||||
unfilled = Math.max(0, 15 - filled);
|
||||
}
|
||||
// Redraw the progress bar every 100 units
|
||||
if (this.current % 100 === 0) {
|
||||
var percentage = 0;
|
||||
var filled = 0;
|
||||
var unfilled = 15;
|
||||
if (this.total) {
|
||||
percentage = Math.floor((this.current / this.total) * 100) + '%';
|
||||
filled = Math.floor((this.current / this.total) * 15);
|
||||
unfilled = Math.max(0, 15 - filled);
|
||||
}
|
||||
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(' [' + (filled ? new Array(filled).join('#') : '') + new Array(unfilled).join(' ') + '] (' + this.current + '/' + (this.total || '??') + ') ' + percentage + ' ');
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(' [' + (filled ? new Array(filled).join('#') : '') + new Array(unfilled).join(' ') + '] (' + this.current + '/' + (this.total || '??') + ') ' + percentage + ' ');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user