Skip to content

Conversation

@howieandersen
Copy link
Contributor

@howieandersen howieandersen commented Nov 28, 2025

Improve validation, duplicate detection, and refactor duplicated code

Description

Duplicate Logic Between Methods
• Extracted the common assignment matching logic into a new static helper method GetMatchingAssignments
• Both RemoveAssignments and ProcessEntityAndAssignmentUpdates now use this shared method
• Added .Distinct() to optimize the query for FromId values

Missing Null Check After Database Query
• Added validation in ProcessEntityAndAssignmentUpdates to check if all expected entities were retrieved
• Logs a warning with the count and IDs of missing entities (limited to first 10 for readability)
• The code continues processing available entities but alerts about missing ones

Inefficient Duplicate Detection Logic
• Changed the logic to add both BEDR and AAFY roles to the seen set first
• Then checks if either failed (meaning it was already present)
• This ensures both roles are properly tracked and prevents the issue where the first call fails and flushes before checking the second

Missing Validation in MapToAssignment
• Added null check for the model parameter
• Validates that FromParty and ToParty are not empty GUIDs
• Validates that RoleIdentifier is not null or whitespace
• Changed exception types to be more specific (ArgumentNullException, ArgumentException, InvalidOperationException)
• Improved error messages to include contextual information

Additional improvements:
• Renamed DoAllTheThings to ProcessEntityAndAssignmentUpdates (more descriptive)
• Fixed typo: "proccessing" → "processing"
• Made the helper method GetMatchingAssignments static since it doesn't use instance state

…actor duplicated code

- Renamed DoAllTheThings to ProcessEntityAndAssignmentUpdates for clarity
- Fixed inefficient duplicate detection logic for parent role tracking (BEDR/AAFY)
- Added null/empty validation in MapToAssignment with specific exception types
- Extracted GetMatchingAssignments helper to eliminate duplicated query logic
- Added validation and logging for missing entities after database queries
- Fixed typo: "proccessing" → "processing"
@howieandersen howieandersen changed the base branch from main to bug/accmgmt-rolesyncservice-replaced-paralleljob November 28, 2025 10:04
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.

1 participant