Skip to content

chore: Batch fetch Owns/WriteOwner - BED-8364#2823

Open
StephenHinck wants to merge 4 commits into
mainfrom
BED-8364
Open

chore: Batch fetch Owns/WriteOwner - BED-8364#2823
StephenHinck wants to merge 4 commits into
mainfrom
BED-8364

Conversation

@StephenHinck
Copy link
Copy Markdown
Contributor

@StephenHinck StephenHinck commented May 26, 2026

Description

During Owns/WriteOwner post-processing, batch-fetch all unique target node IDs into a graph.NodeSet via a single ops.FetchNodeSet query with InIDs before entering the relationship loop. Each iteration then does a local map lookup instead of a DB round-trip. In tested datasets, this change yielded approximately 50% reduction in post-processing duration for these edges.

Motivation and Context

Resolves BED-8364

Why is this change required? What problem does it solve?

How Has This Been Tested?

No changes have been made to existing test suites. Additionally, validated locally with several datasets.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)

Checklist:

Summary by CodeRabbit

  • Performance

    • Improved Active Directory relationship processing by batching target node lookups and de-duplicating referenced targets, reducing redundant fetches and speeding analysis.
  • Bug Fixes

    • If a referenced target is missing from the batched results, the system logs the missing target and skips that relation to avoid extra individual fetch attempts and reduce errors.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: a59e002f-4deb-4d03-8d6f-42a8c47dcf92

📥 Commits

Reviewing files that changed from the base of the PR and between 3c4608e and 68390b9.

📒 Files selected for processing (1)
  • packages/go/analysis/ad/owns.go

📝 Walkthrough

Walkthrough

The PR changes postOwnsEdges and postWriteOwnerEdges to deduplicate relationship EndIDs, bulk-fetch all referenced target nodes via FetchNodeSet, resolve targets from the returned NodeSet, and log+skip relationships whose target is absent; a new collectUniqueEndIDs helper was added. Enforcement and gating checks are unchanged.

Changes

Bulk node fetching optimization

Layer / File(s) Summary
Bulk target node fetching in post-relationships
packages/go/analysis/ad/owns.go
collectUniqueEndIDs deduplicates relationship EndIDs; postOwnsEdges and postWriteOwnerEdges precompute unique target IDs, fetch all matching nodes once via FetchNodeSet, resolve each relationship's target from the prefetched NodeSet, and log+skip missing targets. Existing dsHeuristics enforcement and computer/derived/admin-group gating remain unchanged.

Sequence Diagram

sequenceDiagram
  participant postOwnsEdges
  participant postWriteOwnerEdges
  participant collectUniqueEndIDs
  participant FetchNodeSet
  participant NodeSet
  participant submitEdge

  postOwnsEdges->>collectUniqueEndIDs: collect EndIDs from relationships
  postWriteOwnerEdges->>collectUniqueEndIDs: collect EndIDs from relationships
  collectUniqueEndIDs->>FetchNodeSet: FetchNodeSet(InIDs = unique EndIDs)
  FetchNodeSet->>NodeSet: return NodeSet
  postOwnsEdges->>NodeSet: lookup target by EndID
  postOwnsEdges->>submitEdge: submit Owns edge (if target found & gating)
  postWriteOwnerEdges->>NodeSet: lookup target by EndID
  postWriteOwnerEdges->>submitEdge: submit WriteOwner edge (if target found & gating)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

go

Suggested reviewers

  • superlinkx
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main optimization: batch fetching for Owns/WriteOwner relationships, directly matching the changeset purpose and the associated Jira ticket BED-8364.
Description check ✅ Passed The description covers all required template sections: it explains the technical change, provides motivation (performance improvement), documents testing approach, identifies the change type as a chore, and confirms checklist items are complete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8364

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the go Pull requests that update go code label May 26, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/go/analysis/ad/owns.go (1)

252-263: 💤 Low value

Consider a richer variable name for ids.

Per coding guidelines, prefer rich variable names. Consider renaming ids to uniqueEndIDs or endIDs to make the intent clearer.

♻️ Proposed refactor
 func collectUniqueEndIDs(relationships []*graph.Relationship) []graph.ID {
 	seen := make(map[graph.ID]struct{}, len(relationships))
-	ids := make([]graph.ID, 0, len(relationships))
+	uniqueEndIDs := make([]graph.ID, 0, len(relationships))
 	for _, rel := range relationships {
 		if _, ok := seen[rel.EndID]; !ok {
 			seen[rel.EndID] = struct{}{}
-			ids = append(ids, rel.EndID)
+			uniqueEndIDs = append(uniqueEndIDs, rel.EndID)
 		}
 	}
-	return ids
+	return uniqueEndIDs
 }
🤖 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/owns.go` around lines 252 - 263, In
collectUniqueEndIDs, rename the local slice variable ids to a clearer name
(e.g., uniqueEndIDs or endIDs) to follow naming guidelines and make the intent
explicit; update its declaration and all usages inside the function (the append
and the returned value) so the function still returns the same []graph.ID but
with the clearer identifier.
🤖 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.

Nitpick comments:
In `@packages/go/analysis/ad/owns.go`:
- Around line 252-263: In collectUniqueEndIDs, rename the local slice variable
ids to a clearer name (e.g., uniqueEndIDs or endIDs) to follow naming guidelines
and make the intent explicit; update its declaration and all usages inside the
function (the append and the returned value) so the function still returns the
same []graph.ID but with the clearer identifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 18b8bff1-83cb-40ce-9b98-8a14ede73fc1

📥 Commits

Reviewing files that changed from the base of the PR and between 916ea3d and a803abe.

📒 Files selected for processing (1)
  • packages/go/analysis/ad/owns.go

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/owns.go`:
- Around line 253-254: Group the local variable declarations into a var (...)
block hoisted near the top of the function and rename uniqueEndIds to
uniqueEndIDs to follow Go acronym-casing conventions; specifically replace the
separate statements creating seen := make(map[graph.ID]struct{},
len(relationships)) and uniqueEndIds := make([]graph.ID, 0, len(relationships))
with a var block declaring seen and uniqueEndIDs, then update all references
(e.g., where you compare to rel.EndID) to use uniqueEndIDs.
🪄 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: 785f2aeb-f07f-4f9a-ab60-842abe204b98

📥 Commits

Reviewing files that changed from the base of the PR and between a803abe and 3c4608e.

📒 Files selected for processing (1)
  • packages/go/analysis/ad/owns.go

Comment thread packages/go/analysis/ad/owns.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant