From 4eaead8cbbc452168a43e9507848b7609c2e7170 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 11 Nov 2021 10:10:08 +0300 Subject: New top query fix --- src/main/java/com/juick/TopManager.java | 2 ++ src/main/java/com/juick/service/MessagesServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/TopManager.java b/src/main/java/com/juick/TopManager.java index 3a6cafe1..faa225d8 100644 --- a/src/main/java/com/juick/TopManager.java +++ b/src/main/java/com/juick/TopManager.java @@ -52,6 +52,8 @@ public class TopManager { if (!tags.contains("juick")) { CommandResult result = commandsManager.commandRecommend(serviceUser, URI.create(StringUtils.EMPTY), String.valueOf(m)); logger.info("Popular message {}: {}", m, result.getText()); + } else { + logger.warn("Popular candidates query broken again"); } }); } diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 0a010929..ddf7234e 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -982,12 +982,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ + "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id " + "WHERE COALESCE(messages_tags.tag_id, 0) != 2 " + "AND COALESCE(messages_tags.tag_id, 0) != 805 AND replies.ts > TIMESTAMPADD(HOUR, -2, CURRENT_TIMESTAMP) " - + "AND COALESCE(favorites.user_id, 0) != 2 GROUP BY messages.message_id having COUNT(DISTINCT(replies.user_id)) > 5 " + + "AND NOT EXISTS (SELECT 1 FROM favorites WHERE message_id = messages.message_id AND user_id = 2) GROUP BY messages.message_id having COUNT(DISTINCT(replies.user_id)) > 5 " + "UNION ALL SELECT favorites.message_id FROM favorites " + "INNER JOIN messages ON messages.message_id = favorites.message_id " + "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id " + "WHERE COALESCE(messages_tags.tag_id, 0) != 2 AND favorites.ts > TIMESTAMPADD(HOUR, -2, CURRENT_TIMESTAMP) " - + "AND NOT EXISTS (SELECT * FROM favorites WHERE user_id = 2) GROUP BY messages.message_id HAVING COUNT(DISTINCT favorites.user_id) > 1;", + + "AND NOT EXISTS (SELECT 1 FROM favorites WHERE message_id = messages.message_id AND user_id = 2) GROUP BY messages.message_id HAVING COUNT(DISTINCT favorites.user_id) > 1;", Integer.class); } -- cgit v1.2.3