幸运24-meta-提取公共trimHistory后置调用

This commit is contained in:
2025-08-14 12:05:18 +08:00
parent c9e2bf5edd
commit 168fa60a70
2 changed files with 13 additions and 9 deletions

View File

@@ -91,6 +91,8 @@ public class Lucky24GiftSendService {
receiverList, room, sendGiftTime, null != incomeAllot.getExtraStore());
log.info("[lucky24] uid {}, totalWinGoldNum {}", senderUid, JSON.toJSONString(recordMap));
userMetaService.trimHistory(senderUid);
sendMq(recordMap);
}

View File

@@ -42,6 +42,15 @@ public class Lucky24UserMetaService {
return getUserMeta(uid).getOrDefault(TIMES_KEY, 0L).longValue();
}
public void trimHistory(Long uid){
RList<Lucky24Result> historyQueue = getUserHistoryQueue(uid);
int size = historyQueue.size();
if (size > HISTORY_QUEUE_SIZE){
historyQueue.trim(0, HISTORY_QUEUE_SIZE);
}
historyQueue.expireAsync(Duration.of(7, ChronoUnit.DAYS));
}
public BigDecimal getUserLast2000ProductionRatio(Long uid) {
RList<Lucky24Result> historyQueue = getUserHistoryQueue(uid);
int size = historyQueue.size();
@@ -53,9 +62,7 @@ public class Lucky24UserMetaService {
BigDecimal productionRatio = num > 0 ? BigDecimal.valueOf(historyOutput).divide(BigDecimal.valueOf(historyInput),2, RoundingMode.HALF_UP): BigDecimal.ZERO;
log.info("[lucky24] buildPool last2000 uid {}, historyInput {}, historyOutput {}, num {}, productionRatio {}",
uid, historyInput, historyOutput, num, productionRatio);
if (size > HISTORY_QUEUE_SIZE){
historyQueue.trim(0, HISTORY_QUEUE_SIZE);
}
return productionRatio;
}
@@ -64,11 +71,7 @@ public class Lucky24UserMetaService {
int size = historyQueue.size();
//保留20000条记录
int num = Math.min(size, HISTORY_QUEUE_SIZE);
List<Lucky24Result> historyResult = historyQueue.range(num);
if (size > HISTORY_QUEUE_SIZE){
historyQueue.trim(0, HISTORY_QUEUE_SIZE);
}
return historyResult;
return historyQueue.range(num);
}
public BigDecimal getUserProductionRatio(Long uid) {
@@ -161,7 +164,6 @@ public class Lucky24UserMetaService {
public void updateUserMeta(long senderUid, int partitionId, long input, long output) {
RList<Lucky24Result> historyQueue = getUserHistoryQueue(senderUid);
historyQueue.add(0, new Lucky24Result(null, null, input, output, null));
historyQueue.expire(Duration.of(14, ChronoUnit.DAYS));
if (output > 0L){
getUser10wStat(senderUid).delete();