Authored by mali

优化查询性能

@@ -26,4 +26,6 @@ public interface IInBoxDao { @@ -26,4 +26,6 @@ public interface IInBoxDao {
26 InBox selectNewUserGuideInBox(@Param("tableName")String tableName, @Param("businessType") Integer businessType, @Param("uid") Integer uid); 26 InBox selectNewUserGuideInBox(@Param("tableName")String tableName, @Param("businessType") Integer businessType, @Param("uid") Integer uid);
27 27
28 int insertBatch(@Param("tableName") String tableName, @Param("list") List<InBox> list); 28 int insertBatch(@Param("tableName") String tableName, @Param("list") List<InBox> list);
  29 +
  30 + List<InBox> selectInboxsEx(@Param("tableName")String tableName, @Param("uid") int uid);
29 } 31 }
@@ -79,4 +79,13 @@ @@ -79,4 +79,13 @@
79 79
80 80
81 </insert> 81 </insert>
  82 +
  83 +
  84 + <select id="selectInboxsEx" resultMap="BaseResultMap">
  85 + SELECT
  86 + <include refid="Base_Column_List"/>
  87 + FROM ${tableName} where uid = #{uid} and is_del='N'
  88 + order by id desc
  89 + limit 1
  90 + </select>
82 </mapper> 91 </mapper>
@@ -418,7 +418,7 @@ public class InBoxServiceImpl implements IInBoxService { @@ -418,7 +418,7 @@ public class InBoxServiceImpl implements IInBoxService {
418 RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_VO_LAST_INFO.generateKey(uid); 418 RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_VO_LAST_INFO.generateKey(uid);
419 InBox inbox = redisTemplate.get(inboxKey, InBox.class); 419 InBox inbox = redisTemplate.get(inboxKey, InBox.class);
420 if (null == inbox) { 420 if (null == inbox) {
421 - List<InBox> inBoxes = inBoxDao.selectInboxs(getTableName(uid), null, uid, 0, 1); //查询最新一条未读消息 421 + List<InBox> inBoxes = inBoxDao.selectInboxsEx(getTableName(uid), uid); //查询最新一条未读消息
422 if(CollectionUtils.isNotEmpty(inBoxes)){ 422 if(CollectionUtils.isNotEmpty(inBoxes)){
423 result.put("lastMessage", inBoxes.get(0).getContent()); 423 result.put("lastMessage", inBoxes.get(0).getContent());
424 result.put("createTime", inBoxes.get(0).getCreateTime()); 424 result.put("createTime", inBoxes.get(0).getCreateTime());