Skip to content

Commit

Permalink
fix: azbobbytables issues
Browse files Browse the repository at this point in the history
convert data to psobject to avoid casing problem with hashtables
update get function to use generic list and improve performance over something that looks suspiciously like +=
  • Loading branch information
JohnDuprey committed Feb 26, 2025
1 parent fbcd3c3 commit 05165f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ function Add-CIPPAzDataTableEntity {

foreach ($row in $rows) {
Write-Information "current entity is $($row.RowKey) with $($row.PartitionKey). Our size is $([System.Text.Encoding]::UTF8.GetByteCount($($row | ConvertTo-Json -Compress)))"
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $row
$NewRow = [PSCustomObject]$row
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $NewRow
}
} else {
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $SingleEnt
$NewEnt = [PSCustomObject]$SingleEnt
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $NewEnt
}

} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-Warning ("AzBobbyTables Error")
Write-Information ($SingleEnt | ConvertTo-Json)
throw "Error processing entity: $ErrorMessage Linenumber: $($_.InvocationInfo.ScriptLineNumber)"
}
} else {
Expand Down
14 changes: 7 additions & 7 deletions Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ function Get-CIPPAzDataTableEntity {
}
if (-not $mergedResults[$partitionKey].ContainsKey($entityId)) {
$mergedResults[$partitionKey][$entityId] = @{
Parts = New-Object 'System.Collections.ArrayList'
Parts = [System.Collections.Generic.List[object]]::new()
}
}
$mergedResults[$partitionKey][$entityId]['Parts'].Add($entity) > $null
$mergedResults[$partitionKey][$entityId]['Parts'].Add($entity)
} else {
$partitionKey = $entity.PartitionKey
if (-not $mergedResults.ContainsKey($partitionKey)) {
$mergedResults[$partitionKey] = @{}
}
$mergedResults[$partitionKey][$entity.RowKey] = @{
Entity = $entity
Parts = New-Object 'System.Collections.ArrayList'
Parts = [System.Collections.Generic.List[object]]::new()
}
}
}

$finalResults = @()
$finalResults = [System.Collections.Generic.List[object]]::new()
foreach ($partitionKey in $mergedResults.Keys) {
foreach ($entityId in $mergedResults[$partitionKey].Keys) {
$entityData = $mergedResults[$partitionKey][$entityId]
if ($entityData.Parts.Count -gt 0) {
if (($entityData.Parts | Measure-Object).Count -gt 0) {
$fullEntity = [PSCustomObject]@{}
$parts = $entityData.Parts | Sort-Object PartIndex
foreach ($part in $parts) {
Expand All @@ -60,9 +60,9 @@ function Get-CIPPAzDataTableEntity {
$fullEntity | Add-Member -MemberType NoteProperty -Name 'PartitionKey' -Value $parts[0].PartitionKey -Force
$fullEntity | Add-Member -MemberType NoteProperty -Name 'RowKey' -Value $entityId -Force
$fullEntity | Add-Member -MemberType NoteProperty -Name 'Timestamp' -Value $parts[0].Timestamp -Force
$finalResults = $finalResults + @($fullEntity)
$finalResults.Add($fullEntity)
} else {
$finalResults = $finalResults + @($entityData.Entity)
$FinalResults.Add($entityData.Entity)
}
}
}
Expand Down

0 comments on commit 05165f0

Please sign in to comment.