Authored by mali

性能调优

... ... @@ -13,8 +13,7 @@ import java.util.Map;
*/
public interface IInBoxDao {
@MapKey("type")
Map<Integer,TypeCountInbox> selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel);
int selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel, @Param("type")Integer type);
List<InBox> selectInboxs(@Param("tableName")String tableName, @Param("type") Integer type, @Param("uid") int uid, @Param("rowNo") int rowNo, @Param("limit") int limit);
... ...
... ... @@ -33,9 +33,9 @@
and is_del = 'N' and type = #{type}
</update>
<select id="selectTypeCount" resultMap="TypeCountInboxMap">
SELECT type, count(1) count FROM ${tableName} WHERE uid = #{uid}
and is_read = #{isRead} and is_del = #{isDel} GROUP BY type
<select id="selectTypeCount" resultType="java.lang.Integer">
SELECT count(1) count FROM ${tableName} WHERE uid = #{uid}
and is_read = #{isRead} and is_del = #{isDel} AND type = #{type}
</select>
<select id="selectInboxs" resultMap="BaseResultMap">
SELECT
... ...
package com.yohoufo.user.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
... ... @@ -75,7 +76,7 @@ public class InBoxServiceImpl implements IInBoxService {
return result;
}
//缓存没有则从数据库查
Map<Integer,TypeCountInbox> typeCountMap = inBoxDao.selectTypeCount(getTableName(uid), uid, "N", "N");
Map<Integer,TypeCountInbox> typeCountMap = selectTypeCount(getTableName(uid), uid, "N", "N");
result = new JSONArray();
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
JSONObject obj = new JSONObject();
... ... @@ -90,6 +91,18 @@ public class InBoxServiceImpl implements IInBoxService {
return result;
}
private Map<Integer, TypeCountInbox> selectTypeCount(String tableName, int uid, String isRead, String isDel) {
Map<Integer, TypeCountInbox> result = new HashMap<>();
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
TypeCountInbox inbox = new TypeCountInbox();
int count = inBoxDao.selectTypeCount(tableName, uid, isRead, isDel, typeEnum.getId());
inbox.setCount(count);
inbox.setType(typeEnum.getId());
result.put(typeEnum.getId(), inbox);
}
return result;
}
private void addNewUserGuideMessage(Integer uid) {
log.info("enter addNewUserGuideMessage. uid is {}",uid);
try{
... ...