Skip to content

Commit

Permalink
PowerShellForGitHub: Disable Progress Bar for Invoke-WebRequest (#229)
Browse files Browse the repository at this point in the history
Disables the PowerShell progress bar for the `Invoke-WebRequest` cmdlet calls in the `Invoke-GHRestMethod` and `Invoke-SendTelemetryEvent` functions due to known performance issues in PowerShell 5.1.

Reference: 
[Progress bar can significantly impact cmdlet performance.](PowerShell/PowerShell#2138)

Fixes #227
  • Loading branch information
X-Guardian committed Jun 10, 2020
1 parent 3c642d2 commit 6e794cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ function Invoke-GHRestMethod
}
}

# Disable Progress Bar in function scope during Invoke-WebRequest
$ProgressPreference = 'SilentlyContinue'

[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
$result = Invoke-WebRequest @params

if ($Method -eq 'Delete')
{
Write-Log -Message "Successfully removed." -Level Verbose
Expand Down Expand Up @@ -265,6 +269,9 @@ function Invoke-GHRestMethod

try
{
# Disable Progress Bar in function scope during Invoke-WebRequest
$ProgressPreference = 'SilentlyContinue'

[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
Invoke-WebRequest @params
}
Expand Down
6 changes: 6 additions & 0 deletions Telemetry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ function Invoke-SendTelemetryEvent
$params.Add("TimeoutSec", (Get-GitHubConfiguration -Name WebRequestTimeoutSec))
$params.Add("Body", $bodyAsBytes)

# Disable Progress Bar in function scope during Invoke-WebRequest
$ProgressPreference = 'SilentlyContinue'

$result = Invoke-WebRequest @params
}
}
Expand Down Expand Up @@ -211,6 +214,9 @@ function Invoke-SendTelemetryEvent

try
{
# Disable Progress Bar in function scope during Invoke-WebRequest
$ProgressPreference = 'SilentlyContinue'

Invoke-WebRequest @params
}
catch [System.Net.WebException]
Expand Down

0 comments on commit 6e794cb

Please sign in to comment.