diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java index 2fa27946..919d62b7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java @@ -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;