chore: pre-cache computers with localgroup data - BED-8365#2824
chore: pre-cache computers with localgroup data - BED-8365#2824StephenHinck wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThis PR restricts local-group post-processing to computers that have local group data by adding a helper that computes a bitmap of computers with inbound ChangesLocal groups processing scope optimization
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/go/analysis/ad/post.go`:
- Line 282: Replace the short variable declarations with a grouped var block at
the top of the enclosing function: hoist the new computers variable (currently
created with computers := cardinality.NewBitmap64()) and the variables
introduced in the block around lines 711–715 into a single var (...) declaration
so they are initialized in one place and follow the repository’s Go
initialization rule; use the existing names (e.g., computers and the other local
variable names in that region) and initialize any with zero values or
constructor calls as appropriate inside the var block.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 577955dd-4608-483f-84df-35340f1cb1c6
📒 Files selected for processing (2)
packages/go/analysis/ad/local_groups.gopackages/go/analysis/ad/post.go
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/go/analysis/ad/post.go (1)
713-717: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winGroup variable initializations in a
var (...)block at the top of the function.The short variable declaration should be hoisted to a
varblock at the top of the anonymous function to align with the repository's Go initialization guideline.♻️ Proposed fix
if err := graphDB.ReadTransaction(ctx, func(tx graph.Transaction) error { + var ( + computersWithLocalGroups cardinality.Duplex[uint64] + err error + ) + if excludedGroups, err := FetchAuthUsersAndEveryoneGroups(tx); err != nil { return err } else { localGroupData.ExcludedShortcutGroups = excludedGroups.IDBitmap() localGroupData.ExcludedShortcutGroupsSlice = localGroupData.ExcludedShortcutGroups.Slice() } if computerIDs, err := FetchNodeIDsByKind(tx, ad.Computer); err != nil { return err } else { localGroupData.Computers = computerIDs } - if computersWithLocalGroups, err := FetchComputerIDsWithLocalToComputer(tx); err != nil { + if computersWithLocalGroups, err = FetchComputerIDsWithLocalToComputer(tx); err != nil { return err } else { localGroupData.ComputersWithLocalGroups = computersWithLocalGroups }As per coding guidelines, "Group variable initializations in a
var ( ... )block and hoist them to the top of the function when possible".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/go/analysis/ad/post.go` around lines 713 - 717, Hoist the short var decl from the if into a var block at the top of the anonymous function: declare variables (e.g., var computersWithLocalGroups <appropriate type>; var err error) near the start of the function, then replace the short-declaration if (if computersWithLocalGroups, err := FetchComputerIDsWithLocalToComputer(tx); err != nil { ... }) with an assignment and error check (computersWithLocalGroups, err = FetchComputerIDsWithLocalToComputer(tx); if err != nil { return err } else { localGroupData.ComputersWithLocalGroups = computersWithLocalGroups }), referencing FetchComputerIDsWithLocalToComputer, computersWithLocalGroups, err and localGroupData.ComputersWithLocalGroups.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@packages/go/analysis/ad/post.go`:
- Around line 713-717: Hoist the short var decl from the if into a var block at
the top of the anonymous function: declare variables (e.g., var
computersWithLocalGroups <appropriate type>; var err error) near the start of
the function, then replace the short-declaration if (if
computersWithLocalGroups, err := FetchComputerIDsWithLocalToComputer(tx); err !=
nil { ... }) with an assignment and error check (computersWithLocalGroups, err =
FetchComputerIDsWithLocalToComputer(tx); if err != nil { return err } else {
localGroupData.ComputersWithLocalGroups = computersWithLocalGroups }),
referencing FetchComputerIDsWithLocalToComputer, computersWithLocalGroups, err
and localGroupData.ComputersWithLocalGroups.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: a94101e7-c609-4069-bca4-6541d2e9c5b8
📒 Files selected for processing (1)
packages/go/analysis/ad/post.go
Description
PostCanRDP and PostLocalGroups iterate over localGroupData.Computers — the set of all computer node IDs in the graph. For each computer, they check local group membership to determine RDP/DCOM/PSRemote access. However, computers that have no LocalToComputer edges have no local group data and produce no results, making their processing pure overhead. This will reduce the local edge (AdminTo, CanRDP, etc) post-processing time universally by whatever percentage of computers have local privilege data; in certain cases, this will reduce local post-processing by 100%.
Motivation and Context
Resolves BED-8365
Why is this change required? What problem does it solve?
How Has This Been Tested?
Test suites have remained unchanged. Multiple datasets were validated locally.
Screenshots (optional):
Types of changes
Checklist:
Summary by CodeRabbit