Skip to content

Commit 48875ba

Browse files
committed
Revert "Improve memory management in user and batch processing"
This reverts commit f8670f8.
1 parent f8670f8 commit 48875ba

3 files changed

Lines changed: 5 additions & 24 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ function Add-CIPPAzDataTableEntity {
6565
try {
6666
# Ensure all property values are not null for string properties
6767
if ($SingleEnt -is [hashtable]) {
68-
$keysToRemove = @($SingleEnt.Keys | Where-Object { $null -eq $SingleEnt[$_] })
69-
foreach ($key in $keysToRemove) {
70-
$SingleEnt.Remove($key)
68+
foreach ($key in @($SingleEnt.Keys)) {
69+
if ($null -eq $SingleEnt[$key]) {
70+
$SingleEnt.Remove($key)
71+
}
7172
}
72-
$keysToRemove = $null
7373
} elseif ($SingleEnt -is [PSCustomObject]) {
7474
$propsToRemove = [system.Collections.Generic.List[string]]::new()
7575
foreach ($prop in $SingleEnt.PSObject.Properties) {

Modules/CIPPCore/Public/Add-CIPPDbItem.ps1

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,7 @@ function Add-CIPPDbItem {
110110
# Clear batch variables to free memory
111111
$Entities = $null
112112
$Batch = $null
113-
114-
# Capture memory before GC
115-
$MemoryBeforeGC = [System.GC]::GetTotalMemory($false)
116-
117-
# Force GC between batches to prevent accumulation
118-
[System.GC]::Collect([System.GC]::MaxGeneration, [System.GCCollectionMode]::Forced)
119-
[System.GC]::WaitForPendingFinalizers()
120-
[System.GC]::Collect([System.GC]::MaxGeneration, [System.GCCollectionMode]::Forced)
121-
122-
# Log memory usage after GC
123-
$MemoryAfterGC = [System.GC]::GetTotalMemory($false)
124-
$FreedMB = [math]::Round(($MemoryBeforeGC - $MemoryAfterGC) / 1MB, 2)
125-
$CurrentMemoryMB = [math]::Round($MemoryAfterGC / 1MB, 2)
126-
Write-Information "Batch $([Math]::Ceiling($ProcessedCount / $BatchSize))/$([Math]::Ceiling($TotalCount / $BatchSize)) complete. Processed: $ProcessedCount/$TotalCount | Memory: ${CurrentMemoryMB}MB | Freed: ${FreedMB}MB"
113+
[System.GC]::Collect()
127114
}
128115

129116
}

Modules/CIPPCore/Public/Set-CIPPDBCacheUsers.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ function Set-CIPPDBCacheUsers {
3232
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Cached users successfully' -sev Debug
3333

3434
} catch {
35-
# Cleanup on error to prevent memory leak
36-
if ($null -ne $Users) {
37-
$Users.Clear()
38-
$Users = $null
39-
}
40-
$UsersResponse = $null
4135
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "Failed to cache users: $($_.Exception.Message)" -sev Error -LogData (Get-CippException -Exception $_)
4236
}
4337
}

0 commit comments

Comments
 (0)