Perf: batch Graph requests in guest and privileged-role tests - #1318
Perf: batch Graph requests in guest and privileged-role tests#1318Alf Løkken (alflokken) wants to merge 6 commits into
Conversation
…o-content Refreshed demo content
Rolling up changes for next release
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR optimizes several PowerShell assessment tests by replacing per-item Microsoft Graph calls with batched Graph requests to reduce request volume and improve run time.
Changes:
- Switch guest sponsor lookups to
Invoke-ZtGraphBatchRequest(bulk expand sponsors). - Refactor app/SP owner lookups into a shared helper (
Get-GuestResourceOwner) and batch owner queries. - Batch retrieval of PIM activation notification rules and compute compliance after collecting results.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/powershell/tests/Test-Assessment.21877.ps1 | Batch guest sponsor retrieval and aggregate results in a single pass. |
| src/powershell/tests/Test-Assessment.21868.ps1 | Batch application/service principal owner retrieval via new helper function. |
| src/powershell/tests/Test-Assessment.21818.ps1 | Batch role management rule retrieval and determine failure after consolidating rules. |
|
Thank you for creating this. I ran into the same issue and created #1497 and #1498 before I discovered this PR. Your suggestion of batching API calls is good and it will reduce execution time to some extent, but these tests will still take some time for large tenants because it seems like Instead of batching API calls, I think the better approach would be to store the required information in the first export phase ( |
What
Replace per-item Graph calls (N+1) with batched Invoke-ZtGraphBatchRequest in three assessment tests:
Why
These tests issued one Graph request per user or role, which dominated runtime in larger tenants. Batching (~20 requests per round-trip) significantly reduces execution time without requiring additional permissions.
Behavior change (21818 only)
Implements the existing
TODO, the check now evaluates all roles instead of stopping at the first failure.Pass/fail behavior is unchanged, but failure reports now include all non-compliant roles. The note stating that the check stopped at the first failing role was removed.
Tests 21868 and 21877 are pure performance changes and produce identical results.