Skip to content

Commit

Permalink
fix search user duplication issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed May 22, 2022
1 parent 698cfba commit ac943a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release Notes.
Apollo 2.0.1

------------------
* [Upgrade spring boot to fix search user issue](https://github.com/apolloconfig/apollo/issues/4366)
* [Upgrade spring boot to fix search user issue](https://github.com/apolloconfig/apollo/pull/4366)
* [Fix search user duplication issue](https://github.com/apolloconfig/apollo/pull/4371)
------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/12?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand Down Expand Up @@ -98,7 +100,7 @@ private List<UserPO> findUsers(String keyword) {
if (StringUtils.isEmpty(keyword)) {
return userRepository.findFirst20ByEnabled(1);
}
List<UserPO> users = new ArrayList<>();
Set<UserPO> users = new HashSet<>();
List<UserPO> byUsername = userRepository
.findByUsernameLikeAndEnabled("%" + keyword + "%", 1);
List<UserPO> byUserDisplayName = userRepository
Expand All @@ -109,7 +111,7 @@ private List<UserPO> findUsers(String keyword) {
if (!CollectionUtils.isEmpty(byUserDisplayName)) {
users.addAll(byUserDisplayName);
}
return users;
return new ArrayList<>(users);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.ctrip.framework.apollo.portal.repository.UserRepository;
import com.ctrip.framework.apollo.portal.spi.UserService;

import java.util.HashSet;
import java.util.Set;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -91,7 +93,7 @@ private List<UserPO> findUsers(String keyword) {
if (StringUtils.isEmpty(keyword)) {
return userRepository.findFirst20ByEnabled(1);
}
List<UserPO> users = new ArrayList<>();
Set<UserPO> users = new HashSet<>();
List<UserPO> byUsername = userRepository
.findByUsernameLikeAndEnabled("%" + keyword + "%", 1);
List<UserPO> byUserDisplayName = userRepository
Expand All @@ -102,7 +104,7 @@ private List<UserPO> findUsers(String keyword) {
if (!CollectionUtils.isEmpty(byUserDisplayName)) {
users.addAll(byUserDisplayName);
}
return users;
return new ArrayList<>(users);
}

@Override
Expand Down

0 comments on commit ac943a7

Please sign in to comment.