diff options
author | Vitaly Takmazov | 2022-11-15 20:28:35 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-11-15 20:28:35 +0300 |
commit | 7e391970e2d0b59fb0c351c5fa9907875d68b9a7 (patch) | |
tree | 289db3e73f44756908481bd6dc4ed04d57c4a5cf /src/main/java/com/juick/service/MessagesServiceImpl.java | |
parent | f8fee73767e2e0512cc8ba9da400385b1538f422 (diff) |
MessagesService: remove duplicated tags from getMessages() query
Diffstat (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 17e74123..8251217f 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -773,31 +773,33 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ public List<Message> getMessages(final User visitor, final List<Integer> mids) { if (CollectionUtils.isNotEmpty(mids)) { - List<Message> msgs = getNamedParameterJdbcTemplate().query("WITH RECURSIVE banned(message_id, reply_id) " - + "AS (SELECT message_id, reply_id FROM replies WHERE replies.message_id IN (:ids) " - + "AND (EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :uid AND b.bl_user_id = replies.user_id) " - + "OR EXISTS (SELECT 1 from users u WHERE u.banned = 1 and u.id = replies.user_id and u.id <> :uid)) " - + "UNION ALL SELECT replies.message_id, replies.reply_id FROM replies INNER JOIN banned " - + "ON banned.reply_id = replies.replyto AND replies.reply_id != replies.replyto AND banned.message_id=replies.message_id " - + "WHERE replies.message_id IN (:ids)) " + "SELECT messages.message_id, 0 as rid, 0 as replyto, " - + "messages.user_id,users.nick, 0 as usr_banned, " + "messages.ts," - + "messages.readonly,messages.privacy, messages.replies-COUNT(DISTINCT banned.reply_id) as replies," - + "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, cast(messages.replies as signed)-cast(subscr_messages.last_read_rid as signed) > 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 " + "ON messages.message_id = banned.message_id " - + "LEFT JOIN messages_tags ON messages_tags.message_id=messages_txt.message_id " - + "LEFT JOIN tags ON tags.tag_id=messages_tags.tag_id " - + "WHERE messages.message_id IN (:ids) GROUP BY " - + "messages.message_id, rid, replyto, messages.user_id, users.nick, usr_banned, messages.ts, " - + "messages.readonly, messages.privacy, messages.attach, messages.hidden, " - + "messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, " - + "m_user_uri, msg_reply_uri, html", + var query = "WITH RECURSIVE banned(message_id, reply_id) " + + "AS (SELECT message_id, reply_id FROM replies WHERE replies.message_id IN (:ids) " + + "AND (EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :uid AND b.bl_user_id = replies.user_id) " + + "OR EXISTS (SELECT 1 from users u WHERE u.banned = 1 and u.id = replies.user_id and u.id <> :uid)) " + + "UNION ALL SELECT replies.message_id, replies.reply_id FROM replies INNER JOIN banned " + + "ON banned.reply_id = replies.replyto AND replies.reply_id != replies.replyto AND banned.message_id=replies.message_id " + + "WHERE replies.message_id IN (:ids)) " + "SELECT messages.message_id, 0 as rid, 0 as replyto, " + + "messages.user_id,users.nick, 0 as usr_banned, " + "messages.ts," + + "messages.readonly,messages.privacy, messages.replies-COUNT(DISTINCT banned.reply_id) as replies," + + "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden," + + "GROUP_CONCAT(DISTINCT 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, cast(messages.replies as signed)-cast(subscr_messages.last_read_rid as signed) > 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 " + "ON messages.message_id = banned.message_id " + + "LEFT JOIN messages_tags ON messages_tags.message_id=messages_txt.message_id " + + "LEFT JOIN tags ON tags.tag_id=messages_tags.tag_id " + + "WHERE messages.message_id IN (:ids) GROUP BY " + + "messages.message_id, rid, replyto, messages.user_id, users.nick, usr_banned, messages.ts, " + + "messages.readonly, messages.privacy, messages.attach, messages.hidden, " + + "messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, " + + "m_user_uri, msg_reply_uri, html"; + + List<Message> msgs = getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource("ids", mids).addValue("uid", visitor.getUid()), new MessageMapper()); Map<Integer, Set<Reaction>> likes = updateReactionsFor(mids); |