Skip to content
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

Refactor to encapsulate Recommender logic in the RecommenderPackageFeed #6082

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

jebriede
Copy link
Contributor

@jebriede jebriede commented Oct 4, 2024

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/2530

Description

This refactoring focuses on improving the encapsulation and separation of concerns within the recommender logic for package feeds. The main objective is to move the logic related to the recommender feed from the generalized search object to a specialized recommender feed, thereby simplifying the code and reducing technical debt.

Key Changes:

  • Encapsulation of Recommender Logic: The recommender logic is moved from the search object to a dedicated recommender feed, which now decorates the main feed. This change ensures that the search object no longer needs to handle the intricacies of the recommender logic.
  • Simplification of Search Object: The search object now operates on a single feed instead of handling multiple feeds (main feed and recommender feed). This reduces complexity and potential errors.
  • Deduplication and Combination of Results: The deduplication of package results from the main feed and the recommender feed is now handled within the recommender feed using a more concise approach with LINQ.
  • Private Methods and Internal Logic: Several methods that were previously public and exposed have been made private to encapsulate the logic within the recommender feed.

Benefits:

This refactoring significantly improves code maintainability by isolating the recommender logic, making the codebase easier to understand and manage, and reducing the cognitive load on developers, allowing them to focus on the core responsibilities of the search object without distraction, thereby setting the stage for future enhancements and features.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@jebriede jebriede requested a review from a team as a code owner October 4, 2024 02:52
@jebriede jebriede marked this pull request as draft October 4, 2024 02:53
@microsoft-github-policy-service microsoft-github-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 12, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 17, 2024
@jebriede jebriede marked this pull request as ready for review October 17, 2024 00:21
jgonz120
jgonz120 previously approved these changes Oct 17, 2024
Copy link
Contributor

@jgonz120 jgonz120 left a comment

Choose a reason for hiding this comment

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

Looks good to me! This change definitely feels like it simplifies the code and makes it easier to understand :)

jgonz120
jgonz120 previously approved these changes Oct 17, 2024
jeffkl
jeffkl previously approved these changes Oct 18, 2024
}

private class IdentityIdEqualityComparer : IEqualityComparer<IPackageSearchMetadata>
{
Copy link
Contributor

Choose a reason for hiding this comment

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

A pattern I prefer is to make a private constructor with a static instance to ensure that no one makes extra instances of this

Suggested change
{
{
public static IdentityIdEqualityComparer Instance = new IdentityIdEqualityComparer();
private IdentityIdEqualityComparer()
{
}

Then line 26 can go away and line 107 can use the static singleton

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this a lot, thanks!

@jebriede jebriede dismissed stale reviews from jeffkl and jgonz120 via 057ba14 October 18, 2024 21:35
@jebriede jebriede merged commit 0b0745a into dev Oct 18, 2024
29 checks passed
@jebriede jebriede deleted the dev-jebriede-RefactorRecommenderFeed branch October 18, 2024 22:27
{
}

public bool Equals(IPackageSearchMetadata x, IPackageSearchMetadata y)
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be OrdinalIgnoreCase.

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.

4 participants