Skip to content

Commit b03a0b9

Browse files
committed
Lower max batch size to 500 in Add-CIPPDbItem
Reduced the maximum batch size from 2000 to 500 to prevent out-of-memory errors with large datasets. Updated the information log to include target memory and calculated batch size for better diagnostics.
1 parent 4d5387a commit b03a0b9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPDbItem.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ function Add-CIPPDbItem {
8484
# Use 25% of available memory for batch processing, with min/max bounds
8585
$TargetBatchMemoryMB = [Math]::Max(50, $AvailableMemoryMB * 0.25)
8686
$CalculatedBatchSize = [Math]::Floor(($TargetBatchMemoryMB * 1MB) / $EstimatedItemSizeBytes)
87-
$BatchSize = [Math]::Max(100, [Math]::Min(2000, $CalculatedBatchSize))
87+
# Reduce max to 500 to prevent OOM with large datasets
88+
$BatchSize = [Math]::Max(100, [Math]::Min(500, $CalculatedBatchSize))
8889

8990
$TotalCount = $Data.Count
9091
$ProcessedCount = 0
91-
Write-Information "Adding $TotalCount items of type $Type to CIPP Reporting DB for tenant $TenantFilter | Available Memory: ${AvailableMemoryMB}MB | Batch Size: $BatchSize (est. item size: $([math]::Round($EstimatedItemSizeBytes/1KB, 2))KB)"
92+
Write-Information "Adding $TotalCount items of type $Type to CIPP Reporting DB for tenant $TenantFilter | Available Memory: ${AvailableMemoryMB}MB | Target Memory: ${TargetBatchMemoryMB}MB | Calculated: $CalculatedBatchSize | Batch Size: $BatchSize (est. item size: $([math]::Round($EstimatedItemSizeBytes/1KB, 2))KB)"
9293
for ($i = 0; $i -lt $TotalCount; $i += $BatchSize) {
9394
$BatchEnd = [Math]::Min($i + $BatchSize, $TotalCount)
9495
$Batch = $Data[$i..($BatchEnd - 1)]

0 commit comments

Comments
 (0)