-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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:User_Logout_NPE #153
Merged
crossoverJie
merged 7 commits into
crossoverJie:master
from
cmgyqjj:fix_User_Logout_NPE
Sep 21, 2024
+52
−17
Merged
fix:User_Logout_NPE #153
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cde9300
fix:User_Logout_NPE
cmgyqjj a3be663
Merge branch 'master' into fix_User_Logout_NPE
cmgyqjj 710c1dc
fix:User_Logout_NPE
cmgyqjj b2e9258
Merge branch 'master' into fix_User_Logout_NPE
cmgyqjj 8c925a4
fix:User_Logout_NPE
cmgyqjj d6ee31a
Merge remote-tracking branch 'origin/fix_User_Logout_NPE' into fix_Us…
cmgyqjj 54b815b
fix_User_Logout_NPE
cmgyqjj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ | |||||
|
||||||
import java.util.HashSet; | ||||||
import java.util.Map; | ||||||
import java.util.Optional; | ||||||
import java.util.Set; | ||||||
import java.util.concurrent.ConcurrentHashMap; | ||||||
|
||||||
|
@@ -34,12 +35,12 @@ public class UserInfoCacheServiceImpl implements UserInfoCacheService { | |||||
private RedisTemplate<String,String> redisTemplate ; | ||||||
|
||||||
@Override | ||||||
public CIMUserInfo loadUserInfoByUserId(Long userId) { | ||||||
public Optional<CIMUserInfo> loadUserInfoByUserId(Long userId) { | ||||||
|
||||||
//优先从本地缓存获取 | ||||||
CIMUserInfo cimUserInfo = USER_INFO_MAP.get(userId); | ||||||
if (cimUserInfo != null){ | ||||||
return cimUserInfo ; | ||||||
return Optional.ofNullable(cimUserInfo); | ||||||
} | ||||||
|
||||||
//load redis | ||||||
|
@@ -49,7 +50,7 @@ public CIMUserInfo loadUserInfoByUserId(Long userId) { | |||||
USER_INFO_MAP.put(userId,cimUserInfo) ; | ||||||
} | ||||||
|
||||||
return cimUserInfo; | ||||||
return Optional.ofNullable(cimUserInfo); | ||||||
} | ||||||
|
||||||
@Override | ||||||
|
@@ -71,8 +72,9 @@ public Set<CIMUserInfo> onlineUser() { | |||||
if (set == null){ | ||||||
set = new HashSet<>(64) ; | ||||||
} | ||||||
CIMUserInfo cimUserInfo = loadUserInfoByUserId(Long.valueOf(member)) ; | ||||||
set.add(cimUserInfo) ; | ||||||
Optional<CIMUserInfo> cimUserInfo = loadUserInfoByUserId(Long.valueOf(member)) ; | ||||||
|
||||||
cimUserInfo.ifPresentOrElse(set::add, () -> {}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return set; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It is not recommended to directly use the
java.util.Optional#get
method, as it defeats the purpose of usingOptional
. It is suggested that similar modifications be made in all relevant places.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.
The previously incorrect usage of the non-standard java.util.Optional#get method has been revised upon our re-examination.