Skip to content

Conversation

@laurenleach
Copy link
Contributor

@laurenleach laurenleach commented Dec 24, 2025

Summary by CodeRabbit

  • Improvements
    • Enhanced sub-resource filtering during synchronization operations. Sub-resources are now intelligently filtered based on configured types, improving sync efficiency and reducing unnecessary processing of unconfigured resources.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

Walkthrough

Introduces client-side filtering for sub-resources during traversal in the syncer. A syncResourceTypeMap caches configured sync resource types, and ChildResourceType annotation parsing now conditionally skips pushing sub-resource actions unless the child resource type is in the configured filter.

Changes

Cohort / File(s) Summary
Sub-resource filtering
pkg/sync/syncer.go
Added syncResourceTypeMap for caching configured resource types; modified ChildResourceType annotation parsing to conditionally skip sub-resource actions based on whether child resource type is in syncResourceTypes filter (when non-empty)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through the syncer with filtering grace,
Sub-resources now find their proper place,
A cached map guides the traversal way,
Skipping what's not meant to stay,
Efficient paths through the resource maze!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Filter child resource if resource type not present in filter' directly and accurately describes the main change: adding client-side filtering logic for sub-resources based on syncResourceTypes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lauren/child-resource-type-filter

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

Copy link

@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: 0

🧹 Nitpick comments (1)
pkg/sync/syncer.go (1)

851-854: Consider caching the resource type map to avoid repeated allocations.

The pattern of creating syncResourceTypeMap from s.syncResourceTypes now appears three times in this file (lines 374-379, 786-789, and 851-854). Since getSubResources can be called multiple times during a sync, recreating the map on each invocation is inefficient.

🔎 Proposed refactor to cache the map

Add a cached map field to the syncer struct and initialize it once:

 type syncer struct {
 	c1zManager                          manager.Manager
 	c1zPath                             string
 	externalResourceC1ZPath             string
 	externalResourceEntitlementIdFilter string
 	store                               connectorstore.Writer
 	externalResourceReader              connectorstore.Reader
 	connector                           types.ConnectorClient
 	state                               State
 	runDuration                         time.Duration
 	transitionHandler                   func(s Action)
 	progressHandler                     func(p *Progress)
 	tmpDir                              string
 	skipFullSync                        bool
 	lastCheckPointTime                  time.Time
 	counts                              *ProgressCounts
 	targetedSyncResources               []*v2.Resource
 	onlyExpandGrants                    bool
 	dontExpandGrants                    bool
 	syncID                              string
 	skipEGForResourceType               map[string]bool
 	skipEntitlementsForResourceType     map[string]bool
 	skipEntitlementsAndGrants           bool
 	skipGrants                          bool
 	resourceTypeTraits                  map[string][]v2.ResourceType_Trait
 	syncType                            connectorstore.SyncType
 	injectSyncIDAnnotation              bool
 	setSessionStore                     sessions.SetSessionStore
 	syncResourceTypes                   []string
+	syncResourceTypeMap                 map[string]bool
 }

Then initialize it once in the Sync method after lines 374-379 (or in NewSyncer):

 	syncResourceTypeMap := make(map[string]bool)
 	if len(s.syncResourceTypes) > 0 {
 		for _, rt := range s.syncResourceTypes {
 			syncResourceTypeMap[rt] = true
 		}
 	}
+	s.syncResourceTypeMap = syncResourceTypeMap

And replace all three map creation sites with:

-	syncResourceTypeMap := make(map[string]bool)
-	for _, rt := range s.syncResourceTypes {
-		syncResourceTypeMap[rt] = true
-	}
+	// Use cached map from s.syncResourceTypeMap
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d79dcb4 and 40a7c99.

📒 Files selected for processing (1)
  • pkg/sync/syncer.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/sync/syncer.go (2)
pb/c1/connector/v2/annotation_resource_tree.pb.go (2)
  • ChildResourceType (25-30)
  • ChildResourceType (43-43)
pb/c1/connector/v2/annotation_resource_tree_protoopaque.pb.go (2)
  • ChildResourceType (25-30)
  • ChildResourceType (43-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: go-test (1.25.2, windows-latest)
🔇 Additional comments (1)
pkg/sync/syncer.go (1)

863-867: Filtering logic correctly implements the PR objective.

The implementation properly checks if a resource type filter is configured and skips child resource actions for types not in the filter. This is consistent with the filtering approach used elsewhere in the codebase (e.g., lines 784-797 in SyncResourceTypes).

@laurenleach laurenleach merged commit d6c929e into main Dec 24, 2025
6 checks passed
@laurenleach laurenleach deleted the lauren/child-resource-type-filter branch December 24, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants