Skip to content

Commit

Permalink
GetAppInfo performance (#3195)
Browse files Browse the repository at this point in the history
Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Sep 26, 2023
1 parent eee2317 commit 19df6a3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
8 changes: 4 additions & 4 deletions AppHandling/Run-AlPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,8 @@ $Parameters = @{
"tenant" = $tenant
}
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app'))
$installedAppIds = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfo | Select-Object -ExpandProperty 'AppId')
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedAppIds = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json') | Select-Object -ExpandProperty 'AppId')
}
else {
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | Select-Object -ExpandProperty 'AppId')
Expand Down Expand Up @@ -1329,8 +1329,8 @@ $Parameters = @{
"tenant" = $tenant
}
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app'))
$installedApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfo)
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json'))
$installedAppIds = @($installedApps | ForEach-Object { $_.AppId } )
}
else {
Expand Down
4 changes: 2 additions & 2 deletions CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ try {

Write-Host "Enumerating Apps in CompilerFolder $symbolsPath"
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $symbolsPath '*.app') | Select-Object -ExpandProperty FullName)
$compilerFolderApps = @(GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppInfo)
$compilerFolderApps = @(GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'AppInfoCache.json'))

Write-Host "Enumerating Apps in Symbols Folder $appSymbolsFolder"
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $appSymbolsFolder '*.app') | Select-Object -ExpandProperty FullName)
$existingApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder)
$existingApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $appSymbolsFolder 'AppInfoCache.json'))

$depidx = 0
while ($depidx -lt $dependencies.Count) {
Expand Down
4 changes: 2 additions & 2 deletions CompilerFolderHandling/Copy-AppFilesToCompilerFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function Copy-AppFilesToCompilerFolder {

Write-Host "Copy app files to compiler folder"
$symbolsPath = Join-Path $compilerFolder 'symbols'
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $symbolsPath '*.app'))
$compilerFolderApps = GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppInfo
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $symbolsPath '*.app') | Select-Object -ExpandProperty FullName)
$compilerFolderApps = GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'AppInfoCache.json')
if ($checkAlreadyInstalled) {
$appFiles = @(Sort-AppFilesByDependencies -appFiles $appFiles -includeOnlyAppIds $includeOnlyAppIds -excludeInstalledApps $compilerFolderApps -WarningAction SilentlyContinue)
}
Expand Down
28 changes: 20 additions & 8 deletions HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,19 @@ function GetAppInfo {
Param(
[string[]] $appFiles,
[string] $compilerFolder,
[switch] $cacheAppInfo
[string] $cacheAppInfoPath = ''
)

$appInfoCache = $null
$cacheUpdated = $false
if ($cacheAppInfoPath) {
if (Test-Path $cacheAppInfoPath) {
$appInfoCache = Get-Content -Path $cacheAppInfoPath -Encoding utf8 | ConvertFrom-Json
}
else {
$appInfoCache = @{}
}
}
Write-Host "Getting .app info"
$binPath = Join-Path $compilerFolder 'compiler/extension/bin'
if ($isLinux) {
Expand All @@ -1115,12 +1125,10 @@ function GetAppInfo {
$packageStream = $null
$package = $null
try {
$appFiles | ForEach-Object {
$path = $_
foreach($path in $appFiles) {
Write-Host -NoNewline "- $([System.IO.Path]::GetFileName($path))"
$appInfoPath = "$_.json"
if ($cacheAppInfo -and (Test-Path -Path $appInfoPath)) {
$appInfo = Get-Content -Path $appInfoPath | ConvertFrom-Json
if ($appInfoCache -and $appInfoCache.PSObject.Properties.Name -eq $path) {
$appInfo = $appInfoCache."$path"
Write-Host " (cached)"
}
else {
Expand All @@ -1146,8 +1154,9 @@ function GetAppInfo {
"propagateDependencies" = $manifest.PropagateDependencies
}
Write-Host " (succeeded)"
if ($cacheAppInfo) {
$appInfo | ConvertTo-Json -Depth 99 | Set-Content -Path $appInfoPath -Encoding UTF8 -Force
if ($appInfoCache) {
$appInfoCache | Add-Member -MemberType NoteProperty -Name $path -Value $appInfo
$cacheUpdated = $true
}
}
@{
Expand All @@ -1163,6 +1172,9 @@ function GetAppInfo {
"PropagateDependencies" = $appInfo.propagateDependencies
}
}
if ($cacheUpdated) {
$appInfoCache | ConvertTo-Json -Depth 99 | Set-Content -Path $cacheAppInfoPath -Encoding UTF8 -Force
}
}
catch [System.Reflection.ReflectionTypeLoadException] {
Write-Host " (failed)"
Expand Down

0 comments on commit 19df6a3

Please sign in to comment.