master_zzxx
parent
af542a318c
commit
f7dfec8f3e
|
@ -39,41 +39,53 @@ public class MessageCache {
|
||||||
RedisUtil.getInstence().hset(key,String.valueOf(index),gson.toJson(chatInfo));
|
RedisUtil.getInstence().hset(key,String.valueOf(index),gson.toJson(chatInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ChatProto.ChatInfo> getCrossMsg(long messageId, String group) {
|
public static List<ChatProto.ChatInfo> getCrossMsg(long messageId,String group){
|
||||||
String key = RedisKey.CHAT_CROSS_INFO_CACHE + group;
|
String key = RedisKey.CHAT_CROSS_INFO_CACHE+group;
|
||||||
Map<Object, Object> rawMap = RedisUtil.getInstence().hmget(key);
|
Map<Integer,ChatProto.ChatInfo> map = new HashMap<>();
|
||||||
|
Map<Object, Object> collect = RedisUtil.getInstence().hmget(key);
|
||||||
if (rawMap == null || rawMap.isEmpty()) {
|
collect.entrySet().forEach(o -> map.put(Integer.parseInt(o.getKey().toString()),
|
||||||
return Collections.emptyList();
|
gson.fromJson(o.getValue().toString(),ChatProto.ChatInfo.class)));
|
||||||
}
|
|
||||||
List<ChatProto.ChatInfo> objs = new ArrayList<>();
|
List<ChatProto.ChatInfo> objs = new ArrayList<>();
|
||||||
Object obj = RedisUtil.getInstence().get(RedisKey.CHAT_CROSS_MSG_ID + group);
|
Object obj = RedisUtil.getInstence().get(RedisKey.CHAT_CROSS_MSG_ID + group);
|
||||||
|
if(obj==null){
|
||||||
if (obj == null) {
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
int writeIndex = Integer.parseInt(String.valueOf(obj));
|
int writeIndex = Integer.parseInt(String.valueOf(obj));
|
||||||
int nextIndex = writeIndex % capuatiy; // Assuming capacity is a static value or defined elsewhere
|
|
||||||
|
|
||||||
|
Integer nextIndex = writeIndex%capuatiy;
|
||||||
|
|
||||||
|
if(nextIndex==-1){
|
||||||
|
nextIndex = capuatiy - 1;
|
||||||
|
}
|
||||||
|
if(collect.size()<=0){
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
boolean needCompareTime = (messageId == 0);
|
boolean needCompareTime = (messageId == 0);
|
||||||
|
|
||||||
while (rawMap.containsKey(nextIndex)) {
|
while(map.containsKey(nextIndex)){
|
||||||
String rawValue = String.valueOf(rawMap.get(nextIndex));
|
|
||||||
ChatProto.ChatInfo chatInfo = gson.fromJson(rawValue, ChatProto.ChatInfo.class);
|
|
||||||
|
|
||||||
if (!needCompareTime && messageId >= chatInfo.getMessageId()) {
|
ChatProto.ChatInfo o = map.get(nextIndex);
|
||||||
|
if(!needCompareTime){
|
||||||
|
//比较消息id
|
||||||
|
if(messageId>=o.getMessageId()){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
objs.add(0, o);
|
||||||
|
if(objs.size()>perCaught){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
nextIndex--;
|
||||||
objs.add(0, chatInfo);
|
if(nextIndex == -1){
|
||||||
|
nextIndex = capuatiy - 1;
|
||||||
if (objs.size() > perCaught) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nextIndex = (nextIndex - 1 + capuatiy) % capuatiy;
|
|
||||||
}
|
}
|
||||||
return objs.size() > perCaught ? objs.subList(0, perCaught) : objs;
|
if(!needCompareTime && objs.size()>perCaught){
|
||||||
|
return objs.subList(0,perCaught);
|
||||||
|
}
|
||||||
|
|
||||||
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue