-
Notifications
You must be signed in to change notification settings - Fork 221
Optimize notification configuration to reduce Azure DevOps API calls #13031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
a30ef5c
fe367b7
6722862
6c0dfe2
32234e5
95e6c34
b991644
1719bc1
82eb63d
9f9b142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,8 +24,6 @@ class NotificationConfigurator | |||||||||
|
|
||||||||||
| // A cache on the code owners github identity to owner descriptor. | ||||||||||
| private readonly Dictionary<string, string> contactsCache = new Dictionary<string, string>(); | ||||||||||
| // A cache on the team member to member descriptor. | ||||||||||
| private readonly Dictionary<string, string> teamMemberCache = new Dictionary<string, string>(); | ||||||||||
|
|
||||||||||
| public NotificationConfigurator(AzureDevOpsService service, GitHubService gitHubService, ILogger<NotificationConfigurator> logger) | ||||||||||
| { | ||||||||||
|
|
@@ -121,70 +119,112 @@ private async Task SyncTeamWithCodeownersFile( | |||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Get set of team members in the CODEOWNERS file | ||||||||||
| var contactsDescriptors = new List<string>(); | ||||||||||
| foreach (string contact in contacts) | ||||||||||
| var distinctContacts = contacts | ||||||||||
| .Where(contact => !string.IsNullOrEmpty(contact)) | ||||||||||
| .Distinct() | ||||||||||
| .ToList(); | ||||||||||
|
|
||||||||||
| var contactsDescriptors = await ResolveContactDescriptorsAsync(distinctContacts, gitHubToAADConverter); | ||||||||||
|
|
||||||||||
| var contactsSet = new HashSet<string>(contactsDescriptors.Where(d => d != null)); | ||||||||||
|
|
||||||||||
| var teamDescriptors = await GetTeamMemberDescriptorsAsync(team); | ||||||||||
|
|
||||||||||
| var teamSet = new HashSet<string>(teamDescriptors.Where(d => d != null)); | ||||||||||
|
|
||||||||||
| if (contactsSet.SetEquals(teamSet)) | ||||||||||
| { | ||||||||||
| if (!contactsCache.ContainsKey(contact)) | ||||||||||
| logger.LogInformation("Team membership is already synchronized. No changes needed."); | ||||||||||
|
||||||||||
| logger.LogInformation("Team membership is already synchronized. No changes needed."); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (contactsToRemove.Any()) | |
| { | |
| logger.LogInformation("Removing {count} contact(s) from team", contactsToRemove.Count); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot remove this extra logging you added similarly for the add code path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the aggregate logging for both remove and add operations, and the team sync status message. Changes in 9f9b142.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot why is this more efficient the original GetUserFromId? It seems like we are still making an api call per member to get the descriptor. If so please revert this and go back to what were doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct - GetMemberDescriptorsAsync provided no optimization as it still made one ReadIdentityAsync call per member. Reverted to the original GetUserFromId approach with teamMemberCache in 1719bc1.