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

fix search user duplication issue #4371

Merged
merged 2 commits into from
May 25, 2022

Conversation

nobodyiam
Copy link
Member

What's the purpose of this PR

fix search user duplication issue

Which issue(s) this PR fixes:

Fixes #4370

Brief changelog

  • use set to remove the duplicated records

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

@nobodyiam nobodyiam requested a review from vdiskg May 22, 2022 12:17
@nobodyiam nobodyiam added this to the 2.0.1 milestone May 22, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2022

Codecov Report

Merging #4371 (6fb49f8) into master (698cfba) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##             master    #4371      +/-   ##
============================================
- Coverage     53.19%   53.19%   -0.01%     
- Complexity     2671     2673       +2     
============================================
  Files           489      489              
  Lines         15267    15275       +8     
  Branches       1576     1580       +4     
============================================
+ Hits           8121     8125       +4     
- Misses         6593     6597       +4     
  Partials        553      553              
Impacted Files Coverage Δ
...ollo/portal/spi/oidc/OidcLocalUserServiceImpl.java 0.00% <0.00%> (ø)
.../spi/springsecurity/SpringSecurityUserService.java 0.00% <0.00%> (ø)
...work/apollo/biz/message/DatabaseMessageSender.java 56.25% <0.00%> (-8.34%) ⬇️
...ervice/service/ReleaseMessageServiceWithCache.java 87.05% <0.00%> (+1.17%) ⬆️
...mework/apollo/openapi/service/ConsumerService.java 55.08% <0.00%> (+1.69%) ⬆️
...mework/apollo/portal/component/PortalSettings.java 70.31% <0.00%> (+4.68%) ⬆️
...framework/apollo/openapi/entity/ConsumerAudit.java 48.48% <0.00%> (+6.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 698cfba...6fb49f8. Read the comment docs.

shoothzj
shoothzj previously approved these changes May 22, 2022
@vdiskg
Copy link
Contributor

vdiskg commented May 23, 2022

the com.ctrip.framework.apollo.portal.entity.po.UserPO does not override equals() and hashcode() method cause the Set dosen't work, using a Map might be better.

...
    Map<Long, UserPO> users = new HashMap<>();
    List<UserPO> byUsername = userRepository
        .findByUsernameLikeAndEnabled("%" + keyword + "%", 1);
    List<UserPO> byUserDisplayName = userRepository
        .findByUserDisplayNameLikeAndEnabled("%" + keyword + "%", 1);
    if (!CollectionUtils.isEmpty(byUsername)) {
      for (UserPO user : byUsername) {
        users.put(user.getId(), user);
      }
    }
    if (!CollectionUtils.isEmpty(byUserDisplayName)) {
      for (UserPO user : byUserDisplayName) {
        users.put(user.getId(), user);
      }
    }
    return new ArrayList<>(users.values());

@nobodyiam
Copy link
Member Author

@vdisk-group

It seems the spring entity manager would make the entity object the same, so the HashSet still works.
image

But I agree what you propose is a better solution, so I have changed the implementation to what you suggested. Please help to review again.

Copy link
Contributor

@vdiskg vdiskg left a comment

Choose a reason for hiding this comment

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

LGTM

@nobodyiam nobodyiam merged commit f929541 into apolloconfig:master May 25, 2022
@nobodyiam nobodyiam deleted the fix-search-user-dup-issue branch May 25, 2022 00:53
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search user duplication issue
4 participants