Commit 4a21fdbb by hweeeeeei

优化:根据id查询会话调用频率较高,增加redis缓存,有修改数据库时能同步清空redis该会话数据

parent 55d3156d
...@@ -104,6 +104,14 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -104,6 +104,14 @@ public interface ImConversationService extends BaseService<ImConversation> {
ImConversationQueryVo getImConversationById(Long id); ImConversationQueryVo getImConversationById(Long id);
/** /**
* 删除redis中该会话的缓存
*
* @param id
*/
void deleteCacheImConversationById(Long id);
/**
* 获取分页对象 * 获取分页对象
* *
* @param imConversationPageParam * @param imConversationPageParam
......
...@@ -45,6 +45,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; ...@@ -45,6 +45,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil; import io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -62,6 +65,7 @@ import java.util.Map; ...@@ -62,6 +65,7 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Service @Service
@CacheConfig(cacheNames = "convstn")
public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMapper, ImConversation> implements ImConversationService { public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMapper, ImConversation> implements ImConversationService {
@Autowired @Autowired
...@@ -621,6 +625,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -621,6 +625,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversationById.setName(imConversationNameUpdate.getName()); imConversationById.setName(imConversationNameUpdate.getName());
boolean b = imConversationService.updateById(imConversationById); boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationNameUpdate.getConversationId());
if (b) { if (b) {
// 下发群名称变动事件 // 下发群名称变动事件
...@@ -703,6 +710,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -703,6 +710,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversationById.setAttributes(attributes); imConversationById.setAttributes(attributes);
boolean b = imConversationService.updateById(imConversationById); boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationAttrUpdate.getConversationId());
if (b) { if (b) {
...@@ -785,11 +796,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -785,11 +796,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
} }
@Override @Override
@Cacheable(key = "#p0")
public ImConversationQueryVo getImConversationById(Long id) { public ImConversationQueryVo getImConversationById(Long id) {
return imConversationMapper.getImConversationById(id); return imConversationMapper.getImConversationById(id);
} }
@Override @Override
@CacheEvict(key = "#p0")
public void deleteCacheImConversationById(Long id) {
}
@Override
public Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) throws Exception { public Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) throws Exception {
Page<ImConversationQueryVo> page = new PageInfo<>(imConversationPageParam, OrderItem.desc(getLambdaColumn(ImConversation::getCreateTime))); Page<ImConversationQueryVo> page = new PageInfo<>(imConversationPageParam, OrderItem.desc(getLambdaColumn(ImConversation::getCreateTime)));
IPage<ImConversationQueryVo> iPage = imConversationMapper.getImConversationPageList(page, imConversationPageParam); IPage<ImConversationQueryVo> iPage = imConversationMapper.getImConversationPageList(page, imConversationPageParam);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment