Skip to content

Commit 95de2b1

Browse files
updated clean cache removal
1 parent e687195 commit 95de2b1

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ function Test-CIPPAuditLogRules {
166166
$RecordEndTime = Get-Date
167167
$RecordSeconds = ($RecordEndTime - $RecordStartTime).TotalSeconds
168168
Write-Warning "Task took $RecordSeconds seconds for RowKey $($AuditRecord.id)"
169+
Write-Host "Removing row $($AuditRecord.id) from cache"
170+
$RowEntity = Get-CIPPAzDataTableEntity @CacheWebhooksTable -Filter "PartitionKey eq '$TenantFilter' and RowKey eq '$($Row.id)'"
171+
try {
172+
Write-Information 'Removing processed rows from cache'
173+
if ($AuditRecord.id) {
174+
$RowEntity = Get-CIPPAzDataTableEntity @CacheWebhooksTable -Filter "PartitionKey eq '$TenantFilter' and RowKey eq '$($AuditRecord.id)'"
175+
if ($RowEntity) {
176+
Remove-AzDataTableEntity @CacheWebhooksTable -Entity $RowEntity -Force
177+
Write-Information "Removed row $($AuditRecord.id) from cache"
178+
}
179+
}
180+
} catch {
181+
Write-Information "Error removing rows from cache: $($_.Exception.Message)"
182+
}
169183
}
170184
#write-warning "Processed Data: $(($ProcessedData | Measure-Object).Count) - This should be higher than 0 in many cases, because the where object has not run yet."
171185
#write-warning "Creating filters - $(($ProcessedData.operation | Sort-Object -Unique) -join ',') - $($TenantFilter)"
@@ -239,21 +253,5 @@ function Test-CIPPAuditLogRules {
239253
}
240254
}
241255

242-
# Remove processed rows from the cache table
243-
try {
244-
Write-Information 'Removing processed rows from cache'
245-
foreach ($Row in $Rows) {
246-
if ($Row.id) {
247-
$RowEntity = Get-CIPPAzDataTableEntity @CacheWebhooksTable -Filter "PartitionKey eq '$TenantFilter' and RowKey eq '$($Row.id)'"
248-
if ($RowEntity) {
249-
Remove-AzDataTableEntity @CacheWebhooksTable -Entity $RowEntity -Force
250-
Write-Information "Removed row $($Row.id) from cache"
251-
}
252-
}
253-
}
254-
} catch {
255-
Write-Information "Error removing rows from cache: $($_.Exception.Message)"
256-
}
257-
258256
return $Results
259257
}

0 commit comments

Comments
 (0)