From b1a24fde1acd7639e463b500b311dd1dec9dd9a2 Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Fri, 29 Oct 2021 14:33:25 -0400 Subject: [PATCH] Fixed perfromance and a bug --- base/Reload-MyScripts.ps1 | 7 ++++++- base/src/Packagesz.class.inc.ps1 | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base/Reload-MyScripts.ps1 b/base/Reload-MyScripts.ps1 index bf89c2b..05b6009 100644 --- a/base/Reload-MyScripts.ps1 +++ b/base/Reload-MyScripts.ps1 @@ -79,7 +79,12 @@ catch { Join-Path $(Join-Path $PackagePath profile.d) 'classes.ps1' | Where-Object { Test-Path $_ } | ForEach-Object { . $_ } } -$local:myPackages = Get-MyPackages -ReturnFullPath -IncludeRoot | Get-Item + +# This is a hack that for some reason reduces (at least on one machine) +# this next line from running over 27 seconds, to under 5 seconds. +Invoke-Expression "function __GetMyPackages{$(Get-Content $(Join-Path $(Join-Path $MyPSScriptRoot "base") "Get-MyPackages.ps1") | Out-String )}" +$local:myPackages = __GetMyPackages -ReturnFullPath -IncludeRoot | Get-Item +Remove-Item function:__GetMyPackages $local:myAliases = [ordered]@{} diff --git a/base/src/Packagesz.class.inc.ps1 b/base/src/Packagesz.class.inc.ps1 index 4b70ec5..348b87c 100644 --- a/base/src/Packagesz.class.inc.ps1 +++ b/base/src/Packagesz.class.inc.ps1 @@ -28,7 +28,6 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator { $local:currentSys = [SystemName]::_GetValidValues('',$true,$true); $local:hostname = $(hostname) $local:allCmdlets = Get-Command -ListImported | Select-Object -ExpandProperty Name -Unique - $local:allModules = Get-Module -ListAvailable | Select-Object -ExpandProperty Name -Unique $local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } ) @@ -49,7 +48,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator { $v = $v -and -not $($c.CmdletExists | Where-Object { $allCmdlets -notcontains $_ }) } if( $v -and $c.ModuleExists ) { - $v = $v -and -not $($c.ModuleExists | Where-Object { $allModules -notcontains $_ }) + $v = $v -and -not $($c.ModuleExists | Where-Object { -not (Get-Module -ListAvailable $_ -ErrorAction Ignore) }) } if( $v -and $c.AppExeExists ) { $v = $v -and -not $($c.AppExeExists | Where-Object {