From 53a4aaacf585e70aadd3b1133319a5bb1e08f0c4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 1 Jul 2016 12:27:19 +0300 Subject: fix pm conversations query --- src/main/java/com/juick/server/PMQueries.java | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'src/main/java/com/juick/server') diff --git a/src/main/java/com/juick/server/PMQueries.java b/src/main/java/com/juick/server/PMQueries.java index 772a1c28..74d5df3e 100644 --- a/src/main/java/com/juick/server/PMQueries.java +++ b/src/main/java/com/juick/server/PMQueries.java @@ -69,33 +69,13 @@ public class PMQueries { public static List getPMLastConversationsUsers(JdbcTemplate sql, int uid, int cnt) { List qusers = sql.query("SELECT user_id,unread FROM pm_streams " - + "WHERE user_id_to=? AND unread>0 " - + "ORDER BY lastmessage DESC LIMIT " + cnt, (rs, rowNum) -> { + + "WHERE user_id_to=? " + + "ORDER BY unread DESC, lastmessage DESC LIMIT " + cnt, (rs, rowNum) -> { com.juick.User u = new com.juick.User(); u.setUID(rs.getInt(1)); u.MessagesCount = rs.getInt(2); return u; }, uid); - - if (qusers.size() < cnt) { - List addUsers = sql.query("SELECT user_id,user_id_to " - + "FROM pm_streams WHERE (user_id=? OR user_id_to=?) " - + "AND lastmessage>TIMESTAMPADD(MONTH,-1,NOW()) " - + "ORDER BY lastmessage DESC LIMIT ?", (rs, num) -> { - User u = new com.juick.User(); - int uuid = rs.getInt(1) + rs.getInt(2) - uid; - u.setUID(uuid); - return u; - }, uid, uid, cnt * 2); - for (User addUser : addUsers) { - if (!haveUserInArray(qusers, addUser.getUID())) { - qusers.add(addUser); - if (qusers.size() >= cnt) { - break; - } - } - } - } if (!qusers.isEmpty()) { UserQueries.fillUsersByID(sql, qusers); } -- cgit v1.2.3