Commit ec675e7c by hweeeeeei

优化:根据id查询Application调用频率较高,增加redis缓存前缀缩写为"appl",方法名getById修改为getCacheById增加可读性

parent 4a21fdbb
...@@ -57,7 +57,7 @@ public class FriendEventSender { ...@@ -57,7 +57,7 @@ public class FriendEventSender {
responseModel.setReqId(null); responseModel.setReqId(null);
channelSender.sendMsg(responseModel, receiveClient.getId()); channelSender.sendMsg(responseModel, receiveClient.getId());
ImApplication app = imApplicationService.getById(receiveClient.getFkAppid()); ImApplication app = imApplicationService.getCacheById(receiveClient.getFkAppid());
PushVO pushVO = new PushVO(); PushVO pushVO = new PushVO();
pushVO.setTitle(FRIEND_APPLY_TITLE); pushVO.setTitle(FRIEND_APPLY_TITLE);
...@@ -83,7 +83,7 @@ public class FriendEventSender { ...@@ -83,7 +83,7 @@ public class FriendEventSender {
responseModel.setReqId(null); responseModel.setReqId(null);
channelSender.sendMsg(responseModel, receiveClient.getId()); channelSender.sendMsg(responseModel, receiveClient.getId());
ImApplication app = imApplicationService.getById(receiveClient.getFkAppid()); ImApplication app = imApplicationService.getCacheById(receiveClient.getFkAppid());
PushVO pushVO = new PushVO(); PushVO pushVO = new PushVO();
pushVO.setTitle(FRIEND_APPROVE_TITLE); pushVO.setTitle(FRIEND_APPROVE_TITLE);
......
...@@ -16,39 +16,63 @@ public interface ImApplicationService extends BaseService<ImApplication> { ...@@ -16,39 +16,63 @@ public interface ImApplicationService extends BaseService<ImApplication> {
/** /**
* 根据appKey查询application * 根据id查询应用数据 redis缓存
* *
* @param appKey * @param id
* @return * @return
*/ */
ImApplication getCacheAppByAppKey(String appKey); ImApplication getCacheById(Long id);
/** /**
* * 删除缓
* *
* @param imApplication * @param id
* @return
* @throws Exception
*/ */
boolean saveImApplication(ImApplication imApplication) throws Exception; void deleteCacheById(Long id);
/** /**
* 修改 * 删除缓存
* *
* @param imApplication * @param appKey
*/
void deleteCacheByAppKey(String appKey);
/**
* 根据appKey查询application
*
* @param appKey
* @return * @return
* @throws Exception
*/ */
boolean updateImApplication(ImApplication imApplication) throws Exception; ImApplication getCacheAppByAppKey(String appKey);
/** /**
* 删除 * 保存
* *
* @param id * @param imApplication
* @return * @return
* @throws Exception * @throws Exception
*/ */
boolean deleteImApplication(Long id) throws Exception; boolean saveImApplication(ImApplication imApplication) throws Exception;
// /**
// * 修改
// *
// * @param imApplication
// * @return
// * @throws Exception
// */
// boolean updateImApplication(ImApplication imApplication) throws Exception;
//
// /**
// * 删除
// *
// * @param id
// * @return
// * @throws Exception
// */
// boolean deleteImApplication(Long id) throws Exception;
/** /**
* 根据ID获取查询对象 * 根据ID获取查询对象
......
...@@ -15,6 +15,7 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging; ...@@ -15,6 +15,7 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
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.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; 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;
...@@ -27,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -27,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
*/ */
@Slf4j @Slf4j
@Service @Service
@CacheConfig(cacheNames = "applic") @CacheConfig(cacheNames = "appl")
public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMapper, ImApplication> implements ImApplicationService { public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMapper, ImApplication> implements ImApplicationService {
@Autowired @Autowired
...@@ -35,6 +36,22 @@ public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMappe ...@@ -35,6 +36,22 @@ public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMappe
@Override @Override
@Cacheable(key = "#p0") @Cacheable(key = "#p0")
public ImApplication getCacheById(Long id) {
return super.getById(id);
}
@Override
@CacheEvict(key = "#p0")
public void deleteCacheById(Long id) {
}
@Override
@CacheEvict(key = "#p0")
public void deleteCacheByAppKey(String appKey) {
}
@Override
@Cacheable(key = "#p0")
public ImApplication getCacheAppByAppKey(String appKey) { public ImApplication getCacheAppByAppKey(String appKey) {
ImApplication imApplication = this.getOne( ImApplication imApplication = this.getOne(
new QueryWrapper<ImApplication>().lambda() new QueryWrapper<ImApplication>().lambda()
...@@ -49,17 +66,17 @@ public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMappe ...@@ -49,17 +66,17 @@ public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMappe
return super.save(imApplication); return super.save(imApplication);
} }
@Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
@Override // @Override
public boolean updateImApplication(ImApplication imApplication) throws Exception { // public boolean updateImApplication(ImApplication imApplication) throws Exception {
return super.updateById(imApplication); // return super.updateById(imApplication);
} // }
//
@Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
@Override // @Override
public boolean deleteImApplication(Long id) throws Exception { // public boolean deleteImApplication(Long id) throws Exception {
return super.removeById(id); // return super.removeById(id);
} // }
@Override @Override
public ImApplicationQueryVo getImApplicationById(Long id) throws Exception { public ImApplicationQueryVo getImApplicationById(Long id) throws Exception {
......
...@@ -98,7 +98,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox> ...@@ -98,7 +98,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
Long aLong = imInboxMapper.updateImMsgReceivedByIds(curentClient.getId(), imMsgReceivedUpdate.getMsgIds()); Long aLong = imInboxMapper.updateImMsgReceivedByIds(curentClient.getId(), imMsgReceivedUpdate.getMsgIds());
// 根据appKey查询appid // 根据appKey查询appid
ImApplication application = imApplicationService.getById(curentClient.getFkAppid()); ImApplication application = imApplicationService.getCacheById(curentClient.getFkAppid());
// 内容 // 内容
HashMap<String, String> stringStringHashMap = new HashMap<>(); HashMap<String, String> stringStringHashMap = new HashMap<>();
...@@ -141,7 +141,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox> ...@@ -141,7 +141,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
Long aLong = imInboxMapper.updateImMsgReadByIds(curentClient.getId(), imMsgReadStatusUpdate.getMsgIds()); Long aLong = imInboxMapper.updateImMsgReadByIds(curentClient.getId(), imMsgReadStatusUpdate.getMsgIds());
// 根据appKey查询appid // 根据appKey查询appid
ImApplication application = imApplicationService.getById(curentClient.getFkAppid()); ImApplication application = imApplicationService.getCacheById(curentClient.getFkAppid());
// 内容 // 内容
HashMap<String, String> stringStringHashMap = new HashMap<>(); HashMap<String, String> stringStringHashMap = new HashMap<>();
......
...@@ -162,7 +162,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes ...@@ -162,7 +162,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
ImClient imClientSender = imClientService.getCurentClient(); ImClient imClientSender = imClientService.getCurentClient();
// 查询imApplication // 查询imApplication
ImApplication imApplication = imApplicationService.getById(imClientSender.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(imClientSender.getFkAppid());
if (imApplication == null) { if (imApplication == null) {
log.info("imApplication为空"); log.info("imApplication为空");
return ApiResult.fail(); return ApiResult.fail();
......
...@@ -15,7 +15,6 @@ import com.wecloud.utils.JsonUtils; ...@@ -15,7 +15,6 @@ import com.wecloud.utils.JsonUtils;
import io.geekidea.springbootplus.framework.common.exception.BusinessException; import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
/** /**
* @Description 处理Cmd请求 * @Description 处理Cmd请求
...@@ -87,7 +86,7 @@ public abstract class AbstractImCmdStrategy { ...@@ -87,7 +86,7 @@ public abstract class AbstractImCmdStrategy {
} }
// 查询imApplication // 查询imApplication
ImApplication imApplication = imApplicationService.getById(imClientSender.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(imClientSender.getFkAppid());
if (imApplication == null) { if (imApplication == null) {
log.warn("根据appId: {} 查找不到 imApplication!", imClientSender.getFkAppid()); log.warn("根据appId: {} 查找不到 imApplication!", imClientSender.getFkAppid());
return; return;
......
...@@ -142,7 +142,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -142,7 +142,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
public ApiResult<Boolean> reject(RejectRtcChannelParam rejectRtcChannelParam) { public ApiResult<Boolean> reject(RejectRtcChannelParam rejectRtcChannelParam) {
ImClient client = imClientService.getCurentClient(); ImClient client = imClientService.getCurentClient();
ImApplication imApplication = imApplicationService.getById(client.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
//获取频道内所有client //获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(rejectRtcChannelParam.getChannelId()); List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(rejectRtcChannelParam.getChannelId());
...@@ -169,7 +169,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -169,7 +169,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
ImClient client = imClientService.getCurentClient(); ImClient client = imClientService.getCurentClient();
// 根据appKey查询appid // 根据appKey查询appid
ImApplication imApplication = imApplicationService.getById(client.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
this.leave(leaveRtcChannelParam, client); this.leave(leaveRtcChannelParam, client);
return ApiResult.ok(true); return ApiResult.ok(true);
...@@ -209,7 +209,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -209,7 +209,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
Long rtcChannelId = SnowflakeUtil.getId(); Long rtcChannelId = SnowflakeUtil.getId();
// 根据appKey查询appid // 根据appKey查询appid
ImApplication imApplication = imApplicationService.getById(client.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
// 判断发起方必须在线 // 判断发起方必须在线
boolean onlineStatus = userStateCacheManager.isOnline(client.getId()); boolean onlineStatus = userStateCacheManager.isOnline(client.getId());
...@@ -250,7 +250,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -250,7 +250,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
Long rtcChannelId = SnowflakeUtil.getId(); Long rtcChannelId = SnowflakeUtil.getId();
// 根据appKey查询appid // 根据appKey查询appid
ImApplication imApplication = imApplicationService.getById(client.getFkAppid()); ImApplication imApplication = imApplicationService.getCacheById(client.getFkAppid());
// 判断发起方必须在线 // 判断发起方必须在线
boolean onlineStatus = userStateCacheManager.isOnline(client.getId()); boolean onlineStatus = userStateCacheManager.isOnline(client.getId());
......
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