diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 865cdc3d..4a095b65 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -348,7 +348,15 @@ function Invoke-GHRestMethod if (-not (Get-GitHubConfiguration -Name DisableSmarterObjects)) { - $finalResult = ConvertTo-SmarterObject -InputObject $finalResult + # In the case of getting raw content from the repo, we'll end up with a large object/byte + # array which isn't convertible to a smarter object, but by _trying_ we'll end up wasting + # a lot of time. Let's optimize here by not bothering to send in something that we + # know is definitely not convertible ([int32] on PS5, [long] on PS7). + if (($finalResult -isnot [Object[]]) -or + (($finalResult.Count -gt 0) -and ($finalResult[0] -isnot [int]) -and ($finalResult[0] -isnot [long]))) + { + $finalResult = ConvertTo-SmarterObject -InputObject $finalResult + } } $links = $result.Headers['Link'] -split ',' @@ -900,7 +908,13 @@ filter ConvertTo-SmarterObject return $null } - if ($InputObject -is [System.Collections.IList]) + if (($InputObject -is [int]) -or ($InputObject -is [long])) + { + # In some instances, an int/long was being seen as a [PSCustomObject]. + # This attempts to short-circuit extra work we would have done had that happened. + Write-Output -InputObject $InputObject + } + elseif ($InputObject -is [System.Collections.IList]) { $InputObject | ConvertTo-SmarterObject | diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index 44015009..df62e4f5 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -28,7 +28,6 @@ try for ($i = 0; $i -lt 4; $i++) { $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid().Guid) - Start-Sleep -Seconds 5 } $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed