diff options
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java index f71837a7..751b7fc3 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -870,4 +870,18 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ .addValue("before", before), new MessageMapper()); } + @Transactional(readOnly = true) + @Override + public List<Integer> getPopularCandidates() { + return getJdbcTemplate().queryForList("SELECT replies.message_id FROM replies " + + "INNER JOIN messages ON replies.message_id = messages.message_id " + + "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id " + + "WHERE COALESCE(messages_tags.tag_id, 0) != 2 AND replies.ts > DATE_ADD(now(), INTERVAL -2 HOUR) " + + "AND messages.popular=0 GROUP BY 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 > DATE_ADD(NOW(), INTERVAL -2 HOUR) " + + "GROUP BY message_id HAVING COUNT(DISTINCT favorites.user_id) > 1;", Integer.class); + } } |