From 70810eb92ff7810eb0df133d157078064d666a33 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 8 Dec 2023 14:26:43 +0300 Subject: Do not count recommendations from banned users * Previosly only own message recommendations were filtered, now all message recommendations filter banned users --- src/main/java/com/juick/service/MessagesService.java | 2 +- src/main/java/com/juick/service/MessagesServiceImpl.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index 5574dbbf..6f262dd7 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -76,7 +76,7 @@ public interface MessagesService { Message getReplyByUri(String replyUri); - List> getMessagesRecommendations(Collection mids); + List> getMessagesRecommendations(int visitorUid, Collection mids); @Cacheable(value = "discover", key="{ #visitorUid, #before }") List getAll(int visitorUid, int before); diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 78197a0f..8292f4fd 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -490,16 +490,18 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List> getMessagesRecommendations(final Collection mids) { + public List> getMessagesRecommendations(final int visitorUid, final Collection mids) { return getNamedParameterJdbcTemplate().query( "SELECT DISTINCT favorites.message_id, users.id, users.nick, favorites.user_uri FROM favorites " + "INNER JOIN users ON (favorites.user_id = users.id) " + "INNER JOIN messages m ON favorites.message_id=m.message_id WHERE favorites.like_id=1 " + "AND NOT EXISTS (SELECT 1 FROM bl_users WHERE " + "(user_id = favorites.user_id AND bl_user_id = m.user_id) " - + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id)) " + + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id) " + + (visitorUid > 0 ? " OR (user_id = :visitorUid AND favorites.user_id = bl_user_id)" : "") + + ") " + "AND favorites.message_id IN (:mids)", - new MapSqlParameterSource("mids", mids), (rs, rowNum) -> { + new MapSqlParameterSource("mids", mids).addValue("visitorUid", visitorUid), (rs, rowNum) -> { User user = new User(); user.setUid(rs.getInt(2)); user.setName(rs.getString(3)); @@ -824,7 +826,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msgs.forEach(i -> i.setReactions(likes.get(i.getMid()))); msgs.sort(Comparator.comparing(item -> mids.indexOf(item.getMid()))); msgs.forEach(i -> i.setEntities(MessageUtils.getEntities(i))); - List> allRecommendations = getMessagesRecommendations(mids); + List> allRecommendations = getMessagesRecommendations(uid, mids); msgs.forEach(m -> { m.setRecommendations(new HashSet<>(allRecommendations.stream() .filter(r -> r.getLeft().equals(m.getMid())).map(Pair::getRight).toList())); -- cgit v1.2.3