From 7c242c8505b1080819b13a85a1a80a3f5fe3d7a9 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 17 Jun 2021 00:51:08 +0800 Subject: [PATCH] Use HashTable to reduce significant amount of time wasting in recursing file --- Scripts/post_build.ps1 | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Scripts/post_build.ps1 b/Scripts/post_build.ps1 index ce9944624..28d1d3c42 100644 --- a/Scripts/post_build.ps1 +++ b/Scripts/post_build.ps1 @@ -8,7 +8,8 @@ function Build-Version { if ([string]::IsNullOrEmpty($env:flowVersion)) { $targetPath = Join-Path $solution "Output/Release/Flow.Launcher.dll" -Resolve $v = (Get-Command ${targetPath}).FileVersionInfo.FileVersion - } else { + } + else { $v = $env:flowVersion } @@ -19,9 +20,11 @@ function Build-Version { function Build-Path { if (![string]::IsNullOrEmpty($env:APPVEYOR_BUILD_FOLDER)) { $p = $env:APPVEYOR_BUILD_FOLDER - } elseif (![string]::IsNullOrEmpty($solution)) { + } + elseif (![string]::IsNullOrEmpty($solution)) { $p = $solution - } else { + } + else { $p = Get-Location } @@ -38,13 +41,19 @@ function Copy-Resources ($path) { function Delete-Unused ($path, $config) { $target = "$path\Output\$config" - $included = Get-ChildItem $target -Filter "*.dll" - foreach ($i in $included){ - $deleteList = Get-ChildItem $target\Plugins -Include $i -Recurse | Where { $_.VersionInfo.FileVersion -eq $i.VersionInfo.FileVersion -And $_.Name -eq "$i" } - $deleteList | ForEach-Object{ Write-Host Deleting duplicated $_.Name with version $_.VersionInfo.FileVersion at location $_.Directory.FullName } - $deleteList | Remove-Item + $included = @{} + Get-ChildItem $target -Filter "*.dll" | Get-FileHash | ForEach-Object { $included.Add($_.hash, $true) } + + $deleteList = Get-ChildItem $target\Plugins -Filter "*.dll" -Recurse | + Select-Object Name, VersionInfo, Directory, FullName, @{name = "hash"; expression = { (Get-FileHash $_.FullName).hash } } | + Where-Object { $included.Contains($_.hash) } + + $deleteList | ForEach-Object { + Write-Host Deleting duplicated $_.Name with version $_.VersionInfo.FileVersion at location $_.Directory.FullName } - Remove-Item -Path $target -Include "*.xml" -Recurse + $deleteList | Remove-Item -Path {$_.FullName} + + Remove-Item -Path $target -Include "*.xml" -Recurse } function Validate-Directory ($output) { @@ -89,7 +98,7 @@ function Pack-Squirrel-Installer ($path, $version, $output) { function Publish-Self-Contained ($p) { - $csproj = Join-Path "$p" "Flow.Launcher/Flow.Launcher.csproj" -Resolve + $csproj = Join-Path "$p" "Flow.Launcher/Flow.Launcher.csproj" -Resolve $profile = Join-Path "$p" "Flow.Launcher/Properties/PublishProfiles/Net5.0-SelfContained.pubxml" -Resolve # we call dotnet publish on the main project. @@ -102,7 +111,7 @@ function Main { $v = Build-Version Copy-Resources $p - if ($config -eq "Release"){ + if ($config -eq "Release") { Delete-Unused $p $config