fix: bound active bitmap redis offset
This commit is contained in:
parent
d200011c48
commit
4940e612b5
@ -42,6 +42,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
@RequiredArgsConstructor
|
||||
public class OnlineStatusUploadListener implements MessageListener {
|
||||
|
||||
private static final long ACTIVE_BITMAP_MAX_OFFSET = 50_000_000L;
|
||||
|
||||
private final ExpandService expandService;
|
||||
private final UserSVipGateway userSVipGateway;
|
||||
private final WalletGoldClient walletGoldClient;
|
||||
@ -109,7 +111,7 @@ public class OnlineStatusUploadListener implements MessageListener {
|
||||
}
|
||||
|
||||
private void countActiveUser(UserProfile userProfile) {
|
||||
long account = Objects.hash(userProfile.getAccount());
|
||||
long account = activeBitmapOffset(userProfile.getAccount());
|
||||
if (userProfileGateway.checkTeamMember(userProfile.getId())) {
|
||||
countUserActiveIndexService.countAnchorActiveUser(account);
|
||||
countUserActiveIndexService.countAnchorActiveUser(userProfile.getOriginSys(), account);
|
||||
@ -120,6 +122,20 @@ public class OnlineStatusUploadListener implements MessageListener {
|
||||
countUserActiveIndexService.countOrdinaryActiveUser(userProfile.getOriginSys(), account);
|
||||
}
|
||||
|
||||
private long activeBitmapOffset(String account) {
|
||||
if (StringUtils.isNumeric(account)) {
|
||||
try {
|
||||
long offset = Long.parseLong(account);
|
||||
if (offset >= 0 && offset <= ACTIVE_BITMAP_MAX_OFFSET) {
|
||||
return offset;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Keep unusual account ids bounded instead of expanding Redis bitmaps.
|
||||
}
|
||||
}
|
||||
return Math.floorMod(Objects.hashCode(account), ACTIVE_BITMAP_MAX_OFFSET);
|
||||
}
|
||||
|
||||
private void addOnlineUser(UserOnlineStatusEvent event, UserProfile userProfile) {
|
||||
if (StringUtils.isBlank(event.getSessionId())) {
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user