From ae550feea0394bfff147fa1946cfa8c357eacb8a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 2 Oct 2019 00:24:57 +0300 Subject: Fill Message::unread in single query --- src/main/java/com/juick/service/MessagesServiceImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 95d5d1bf..a190a112 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -116,6 +116,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msg.setUpdatedAt(rs.getTimestamp(21).toInstant()); msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(24)).orElse(StringUtils.EMPTY))); msg.setHtml(rs.getBoolean(25)); + msg.setUnread(rs.getBoolean(26)); if (StringUtils.isNotEmpty(msg.getAttachmentType())) { try { imagesService.setAttachmentMetadata(baseImagesUrl, msg); @@ -380,7 +381,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "messages.readonly, messages.privacy, messages.replies," + "messages.attach, COUNT(DISTINCT favorites.user_id) as likes, messages.hidden," + "GROUP_CONCAT(tags.name SEPARATOR ' '), txt.repliesby, txt.txt, '' as q, messages.updated as updated, 0 as to_uid, " - + "NULL as to_name, txt.updated_at, '' as reply_user_uri, '' as to_uri, '' as reply_uri, 0 as html FROM messages " + + "NULL as to_name, txt.updated_at, '' as reply_user_uri, '' as to_uri, '' as reply_uri, 0 as html, 0 as unread FROM messages " + "INNER JOIN users ON messages.user_id = users.id " + "INNER JOIN messages_txt AS txt " + "ON messages.message_id = txt.message_id " @@ -390,7 +391,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "LEFT JOIN tags ON tags.tag_id=messages_tags.tag_id " + "WHERE messages.message_id = ? AND users.banned = 0 " + "GROUP BY mid, rid, replyto, uid, nick, banned, messages.ts, readonly, " - + "privacy, replies, attach, repliesby, q, updated_at, reply_user_uri, to_uri, reply_uri, html", + + "privacy, replies, attach, repliesby, q, updated_at, reply_user_uri, to_uri, reply_uri, html, unread", new MessageMapper(), mid); if (!list.isEmpty()) { @@ -895,10 +896,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden," + "GROUP_CONCAT(tags.name SEPARATOR ' '), messages_txt.repliesby, messages_txt.txt, '' as q, " + "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as m_user_uri, " - + "'' as to_uri, '' as msg_reply_uri, 0 as html " + + "'' as to_uri, '' as msg_reply_uri, 0 as html, messages.replies-subscr_messages.last_read_rid>0 as unread " + "FROM (messages INNER JOIN messages_txt " + "ON messages.message_id=messages_txt.message_id) " + "INNER JOIN users ON messages.user_id=users.id " + + "LEFT JOIN subscr_messages " + + "ON messages.message_id=subscr_messages.message_id AND subscr_messages.suser_id=:uid " + "LEFT JOIN favorites " + "ON messages.message_id = favorites.message_id AND favorites.like_id=1 " + "LEFT JOIN banned " @@ -988,7 +991,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ "NOW(), " + "COALESCE(qw.user_id, m.user_id) as to_uid, COALESCE(qu.nick, mu.nick) as to_name, " + "replies.updated_at, replies.user_uri as uri, " + - "qw.user_uri as to_uri, replies.reply_uri, replies.html " + + "qw.user_uri as to_uri, replies.reply_uri, replies.html, 0 as unread " + "FROM replies LEFT JOIN users " + "ON replies.user_id = users.id " + "LEFT JOIN replies qw ON replies.message_id = qw.message_id and replies.replyto = qw.reply_id " + -- cgit v1.2.3